fed up with those stupid warnings
[mmotm.git] / kernel / sysctl.c
blobdfa213360eaa96b8ed0c15691ad56b31f56ae5d1
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/ratelimit.h>
40 #include <linux/hugetlb.h>
41 #include <linux/initrd.h>
42 #include <linux/key.h>
43 #include <linux/times.h>
44 #include <linux/limits.h>
45 #include <linux/dcache.h>
46 #include <linux/syscalls.h>
47 #include <linux/vmstat.h>
48 #include <linux/nfs_fs.h>
49 #include <linux/acpi.h>
50 #include <linux/reboot.h>
51 #include <linux/ftrace.h>
52 #include <linux/slow-work.h>
53 #include <linux/perf_event.h>
55 #include <asm/uaccess.h>
56 #include <asm/processor.h>
58 #ifdef CONFIG_X86
59 #include <asm/nmi.h>
60 #include <asm/stacktrace.h>
61 #include <asm/io.h>
62 #endif
64 static int deprecated_sysctl_warning(struct __sysctl_args *args);
66 #if defined(CONFIG_SYSCTL)
68 /* External variables not in a header file. */
69 extern int C_A_D;
70 extern int print_fatal_signals;
71 extern int sysctl_overcommit_memory;
72 extern int sysctl_overcommit_ratio;
73 extern int sysctl_panic_on_oom;
74 extern int sysctl_oom_kill_allocating_task;
75 extern int sysctl_oom_dump_tasks;
76 extern int max_threads;
77 extern int core_uses_pid;
78 extern int suid_dumpable;
79 extern char core_pattern[];
80 extern unsigned int core_pipe_limit;
81 extern int pid_max;
82 extern int min_free_kbytes;
83 extern int pid_max_min, pid_max_max;
84 extern int sysctl_drop_caches;
85 extern int percpu_pagelist_fraction;
86 extern int compat_log;
87 extern int latencytop_enabled;
88 extern int sysctl_nr_open_min, sysctl_nr_open_max;
89 #ifndef CONFIG_MMU
90 extern int sysctl_nr_trim_pages;
91 #endif
92 #ifdef CONFIG_RCU_TORTURE_TEST
93 extern int rcutorture_runnable;
94 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
95 #ifdef CONFIG_BLOCK
96 extern int blk_iopoll_enabled;
97 #endif
99 /* Constants used for minimum and maximum */
100 #ifdef CONFIG_DETECT_SOFTLOCKUP
101 static int sixty = 60;
102 static int neg_one = -1;
103 #endif
105 static int zero;
106 static int __maybe_unused one = 1;
107 static int __maybe_unused two = 2;
108 static unsigned long one_ul = 1;
109 static int one_hundred = 100;
110 #ifdef CONFIG_PRINTK
111 static int ten_thousand = 10000;
112 #endif
114 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
115 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
117 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
118 static int maxolduid = 65535;
119 static int minolduid;
120 static int min_percpu_pagelist_fract = 8;
122 static int ngroups_max = NGROUPS_MAX;
124 #ifdef CONFIG_MODULES
125 extern char modprobe_path[];
126 extern int modules_disabled;
127 #endif
128 #ifdef CONFIG_CHR_DEV_SG
129 extern int sg_big_buff;
130 #endif
132 #ifdef CONFIG_SPARC
133 #include <asm/system.h>
134 #endif
136 #ifdef CONFIG_SPARC64
137 extern int sysctl_tsb_ratio;
138 #endif
140 #ifdef __hppa__
141 extern int pwrsw_enabled;
142 extern int unaligned_enabled;
143 #endif
145 #ifdef CONFIG_S390
146 #ifdef CONFIG_MATHEMU
147 extern int sysctl_ieee_emulation_warnings;
148 #endif
149 extern int sysctl_userprocess_debug;
150 extern int spin_retry;
151 #endif
153 #ifdef CONFIG_BSD_PROCESS_ACCT
154 extern int acct_parm[];
155 #endif
157 #ifdef CONFIG_IA64
158 extern int no_unaligned_warning;
159 extern int unaligned_dump_stack;
160 #endif
162 extern struct ratelimit_state printk_ratelimit_state;
164 #ifdef CONFIG_RT_MUTEXES
165 extern int max_lock_depth;
166 #endif
168 #ifdef CONFIG_PROC_SYSCTL
169 static int proc_do_cad_pid(struct ctl_table *table, int write,
170 void __user *buffer, size_t *lenp, loff_t *ppos);
171 static int proc_taint(struct ctl_table *table, int write,
172 void __user *buffer, size_t *lenp, loff_t *ppos);
173 #endif
175 static struct ctl_table root_table[];
176 static struct ctl_table_root sysctl_table_root;
177 static struct ctl_table_header root_table_header = {
178 .count = 1,
179 .ctl_table = root_table,
180 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
181 .root = &sysctl_table_root,
182 .set = &sysctl_table_root.default_set,
184 static struct ctl_table_root sysctl_table_root = {
185 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
186 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
189 static struct ctl_table kern_table[];
190 static struct ctl_table vm_table[];
191 static struct ctl_table fs_table[];
192 static struct ctl_table debug_table[];
193 static struct ctl_table dev_table[];
194 extern struct ctl_table random_table[];
195 #ifdef CONFIG_INOTIFY_USER
196 extern struct ctl_table inotify_table[];
197 #endif
198 #ifdef CONFIG_EPOLL
199 extern struct ctl_table epoll_table[];
200 #endif
202 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
203 int sysctl_legacy_va_layout;
204 #endif
206 extern int prove_locking;
207 extern int lock_stat;
209 /* The default sysctl tables: */
211 static struct ctl_table root_table[] = {
213 .ctl_name = CTL_KERN,
214 .procname = "kernel",
215 .mode = 0555,
216 .child = kern_table,
219 .ctl_name = CTL_VM,
220 .procname = "vm",
221 .mode = 0555,
222 .child = vm_table,
225 .ctl_name = CTL_FS,
226 .procname = "fs",
227 .mode = 0555,
228 .child = fs_table,
231 .ctl_name = CTL_DEBUG,
232 .procname = "debug",
233 .mode = 0555,
234 .child = debug_table,
237 .ctl_name = CTL_DEV,
238 .procname = "dev",
239 .mode = 0555,
240 .child = dev_table,
243 * NOTE: do not add new entries to this table unless you have read
244 * Documentation/sysctl/ctl_unnumbered.txt
246 { .ctl_name = 0 }
249 #ifdef CONFIG_SCHED_DEBUG
250 static int min_sched_granularity_ns = 100000; /* 100 usecs */
251 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
252 static int min_wakeup_granularity_ns; /* 0 usecs */
253 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
254 #endif
256 static struct ctl_table kern_table[] = {
258 .ctl_name = CTL_UNNUMBERED,
259 .procname = "sched_child_runs_first",
260 .data = &sysctl_sched_child_runs_first,
261 .maxlen = sizeof(unsigned int),
262 .mode = 0644,
263 .proc_handler = &proc_dointvec,
265 #ifdef CONFIG_SCHED_DEBUG
267 .ctl_name = CTL_UNNUMBERED,
268 .procname = "sched_min_granularity_ns",
269 .data = &sysctl_sched_min_granularity,
270 .maxlen = sizeof(unsigned int),
271 .mode = 0644,
272 .proc_handler = &sched_nr_latency_handler,
273 .strategy = &sysctl_intvec,
274 .extra1 = &min_sched_granularity_ns,
275 .extra2 = &max_sched_granularity_ns,
278 .ctl_name = CTL_UNNUMBERED,
279 .procname = "sched_latency_ns",
280 .data = &sysctl_sched_latency,
281 .maxlen = sizeof(unsigned int),
282 .mode = 0644,
283 .proc_handler = &sched_nr_latency_handler,
284 .strategy = &sysctl_intvec,
285 .extra1 = &min_sched_granularity_ns,
286 .extra2 = &max_sched_granularity_ns,
289 .ctl_name = CTL_UNNUMBERED,
290 .procname = "sched_wakeup_granularity_ns",
291 .data = &sysctl_sched_wakeup_granularity,
292 .maxlen = sizeof(unsigned int),
293 .mode = 0644,
294 .proc_handler = &proc_dointvec_minmax,
295 .strategy = &sysctl_intvec,
296 .extra1 = &min_wakeup_granularity_ns,
297 .extra2 = &max_wakeup_granularity_ns,
300 .ctl_name = CTL_UNNUMBERED,
301 .procname = "sched_shares_ratelimit",
302 .data = &sysctl_sched_shares_ratelimit,
303 .maxlen = sizeof(unsigned int),
304 .mode = 0644,
305 .proc_handler = &proc_dointvec,
308 .ctl_name = CTL_UNNUMBERED,
309 .procname = "sched_shares_thresh",
310 .data = &sysctl_sched_shares_thresh,
311 .maxlen = sizeof(unsigned int),
312 .mode = 0644,
313 .proc_handler = &proc_dointvec_minmax,
314 .strategy = &sysctl_intvec,
315 .extra1 = &zero,
318 .ctl_name = CTL_UNNUMBERED,
319 .procname = "sched_features",
320 .data = &sysctl_sched_features,
321 .maxlen = sizeof(unsigned int),
322 .mode = 0644,
323 .proc_handler = &proc_dointvec,
326 .ctl_name = CTL_UNNUMBERED,
327 .procname = "sched_migration_cost",
328 .data = &sysctl_sched_migration_cost,
329 .maxlen = sizeof(unsigned int),
330 .mode = 0644,
331 .proc_handler = &proc_dointvec,
334 .ctl_name = CTL_UNNUMBERED,
335 .procname = "sched_nr_migrate",
336 .data = &sysctl_sched_nr_migrate,
337 .maxlen = sizeof(unsigned int),
338 .mode = 0644,
339 .proc_handler = &proc_dointvec,
342 .ctl_name = CTL_UNNUMBERED,
343 .procname = "sched_time_avg",
344 .data = &sysctl_sched_time_avg,
345 .maxlen = sizeof(unsigned int),
346 .mode = 0644,
347 .proc_handler = &proc_dointvec,
350 .ctl_name = CTL_UNNUMBERED,
351 .procname = "timer_migration",
352 .data = &sysctl_timer_migration,
353 .maxlen = sizeof(unsigned int),
354 .mode = 0644,
355 .proc_handler = &proc_dointvec_minmax,
356 .strategy = &sysctl_intvec,
357 .extra1 = &zero,
358 .extra2 = &one,
360 #endif
362 .ctl_name = CTL_UNNUMBERED,
363 .procname = "sched_rt_period_us",
364 .data = &sysctl_sched_rt_period,
365 .maxlen = sizeof(unsigned int),
366 .mode = 0644,
367 .proc_handler = &sched_rt_handler,
370 .ctl_name = CTL_UNNUMBERED,
371 .procname = "sched_rt_runtime_us",
372 .data = &sysctl_sched_rt_runtime,
373 .maxlen = sizeof(int),
374 .mode = 0644,
375 .proc_handler = &sched_rt_handler,
378 .ctl_name = CTL_UNNUMBERED,
379 .procname = "sched_compat_yield",
380 .data = &sysctl_sched_compat_yield,
381 .maxlen = sizeof(unsigned int),
382 .mode = 0644,
383 .proc_handler = &proc_dointvec,
385 #ifdef CONFIG_PROVE_LOCKING
387 .ctl_name = CTL_UNNUMBERED,
388 .procname = "prove_locking",
389 .data = &prove_locking,
390 .maxlen = sizeof(int),
391 .mode = 0644,
392 .proc_handler = &proc_dointvec,
394 #endif
395 #ifdef CONFIG_LOCK_STAT
397 .ctl_name = CTL_UNNUMBERED,
398 .procname = "lock_stat",
399 .data = &lock_stat,
400 .maxlen = sizeof(int),
401 .mode = 0644,
402 .proc_handler = &proc_dointvec,
404 #endif
406 .ctl_name = KERN_PANIC,
407 .procname = "panic",
408 .data = &panic_timeout,
409 .maxlen = sizeof(int),
410 .mode = 0644,
411 .proc_handler = &proc_dointvec,
414 .ctl_name = KERN_CORE_USES_PID,
415 .procname = "core_uses_pid",
416 .data = &core_uses_pid,
417 .maxlen = sizeof(int),
418 .mode = 0644,
419 .proc_handler = &proc_dointvec,
422 .ctl_name = KERN_CORE_PATTERN,
423 .procname = "core_pattern",
424 .data = core_pattern,
425 .maxlen = CORENAME_MAX_SIZE,
426 .mode = 0644,
427 .proc_handler = &proc_dostring,
428 .strategy = &sysctl_string,
431 .ctl_name = CTL_UNNUMBERED,
432 .procname = "core_pipe_limit",
433 .data = &core_pipe_limit,
434 .maxlen = sizeof(unsigned int),
435 .mode = 0644,
436 .proc_handler = &proc_dointvec,
438 #ifdef CONFIG_PROC_SYSCTL
440 .procname = "tainted",
441 .maxlen = sizeof(long),
442 .mode = 0644,
443 .proc_handler = &proc_taint,
445 #endif
446 #ifdef CONFIG_LATENCYTOP
448 .procname = "latencytop",
449 .data = &latencytop_enabled,
450 .maxlen = sizeof(int),
451 .mode = 0644,
452 .proc_handler = &proc_dointvec,
454 #endif
455 #ifdef CONFIG_BLK_DEV_INITRD
457 .ctl_name = KERN_REALROOTDEV,
458 .procname = "real-root-dev",
459 .data = &real_root_dev,
460 .maxlen = sizeof(int),
461 .mode = 0644,
462 .proc_handler = &proc_dointvec,
464 #endif
466 .ctl_name = CTL_UNNUMBERED,
467 .procname = "print-fatal-signals",
468 .data = &print_fatal_signals,
469 .maxlen = sizeof(int),
470 .mode = 0644,
471 .proc_handler = &proc_dointvec,
473 #ifdef CONFIG_SPARC
475 .ctl_name = KERN_SPARC_REBOOT,
476 .procname = "reboot-cmd",
477 .data = reboot_command,
478 .maxlen = 256,
479 .mode = 0644,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
484 .ctl_name = KERN_SPARC_STOP_A,
485 .procname = "stop-a",
486 .data = &stop_a_enabled,
487 .maxlen = sizeof (int),
488 .mode = 0644,
489 .proc_handler = &proc_dointvec,
492 .ctl_name = KERN_SPARC_SCONS_PWROFF,
493 .procname = "scons-poweroff",
494 .data = &scons_pwroff,
495 .maxlen = sizeof (int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
499 #endif
500 #ifdef CONFIG_SPARC64
502 .ctl_name = CTL_UNNUMBERED,
503 .procname = "tsb-ratio",
504 .data = &sysctl_tsb_ratio,
505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
509 #endif
510 #ifdef __hppa__
512 .ctl_name = KERN_HPPA_PWRSW,
513 .procname = "soft-power",
514 .data = &pwrsw_enabled,
515 .maxlen = sizeof (int),
516 .mode = 0644,
517 .proc_handler = &proc_dointvec,
520 .ctl_name = KERN_HPPA_UNALIGNED,
521 .procname = "unaligned-trap",
522 .data = &unaligned_enabled,
523 .maxlen = sizeof (int),
524 .mode = 0644,
525 .proc_handler = &proc_dointvec,
527 #endif
529 .ctl_name = KERN_CTLALTDEL,
530 .procname = "ctrl-alt-del",
531 .data = &C_A_D,
532 .maxlen = sizeof(int),
533 .mode = 0644,
534 .proc_handler = &proc_dointvec,
536 #ifdef CONFIG_FUNCTION_TRACER
538 .ctl_name = CTL_UNNUMBERED,
539 .procname = "ftrace_enabled",
540 .data = &ftrace_enabled,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = &ftrace_enable_sysctl,
545 #endif
546 #ifdef CONFIG_STACK_TRACER
548 .ctl_name = CTL_UNNUMBERED,
549 .procname = "stack_tracer_enabled",
550 .data = &stack_tracer_enabled,
551 .maxlen = sizeof(int),
552 .mode = 0644,
553 .proc_handler = &stack_trace_sysctl,
555 #endif
556 #ifdef CONFIG_TRACING
558 .ctl_name = CTL_UNNUMBERED,
559 .procname = "ftrace_dump_on_oops",
560 .data = &ftrace_dump_on_oops,
561 .maxlen = sizeof(int),
562 .mode = 0644,
563 .proc_handler = &proc_dointvec,
565 #endif
566 #ifdef CONFIG_MODULES
568 .ctl_name = KERN_MODPROBE,
569 .procname = "modprobe",
570 .data = &modprobe_path,
571 .maxlen = KMOD_PATH_LEN,
572 .mode = 0644,
573 .proc_handler = &proc_dostring,
574 .strategy = &sysctl_string,
577 .ctl_name = CTL_UNNUMBERED,
578 .procname = "modules_disabled",
579 .data = &modules_disabled,
580 .maxlen = sizeof(int),
581 .mode = 0644,
582 /* only handle a transition from default "0" to "1" */
583 .proc_handler = &proc_dointvec_minmax,
584 .extra1 = &one,
585 .extra2 = &one,
587 #endif
588 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
590 .ctl_name = KERN_HOTPLUG,
591 .procname = "hotplug",
592 .data = &uevent_helper,
593 .maxlen = UEVENT_HELPER_PATH_LEN,
594 .mode = 0644,
595 .proc_handler = &proc_dostring,
596 .strategy = &sysctl_string,
598 #endif
599 #ifdef CONFIG_CHR_DEV_SG
601 .ctl_name = KERN_SG_BIG_BUFF,
602 .procname = "sg-big-buff",
603 .data = &sg_big_buff,
604 .maxlen = sizeof (int),
605 .mode = 0444,
606 .proc_handler = &proc_dointvec,
608 #endif
609 #ifdef CONFIG_BSD_PROCESS_ACCT
611 .ctl_name = KERN_ACCT,
612 .procname = "acct",
613 .data = &acct_parm,
614 .maxlen = 3*sizeof(int),
615 .mode = 0644,
616 .proc_handler = &proc_dointvec,
618 #endif
619 #ifdef CONFIG_MAGIC_SYSRQ
621 .ctl_name = KERN_SYSRQ,
622 .procname = "sysrq",
623 .data = &__sysrq_enabled,
624 .maxlen = sizeof (int),
625 .mode = 0644,
626 .proc_handler = &proc_dointvec,
628 #endif
629 #ifdef CONFIG_PROC_SYSCTL
631 .procname = "cad_pid",
632 .data = NULL,
633 .maxlen = sizeof (int),
634 .mode = 0600,
635 .proc_handler = &proc_do_cad_pid,
637 #endif
639 .ctl_name = KERN_MAX_THREADS,
640 .procname = "threads-max",
641 .data = &max_threads,
642 .maxlen = sizeof(int),
643 .mode = 0644,
644 .proc_handler = &proc_dointvec,
647 .ctl_name = KERN_RANDOM,
648 .procname = "random",
649 .mode = 0555,
650 .child = random_table,
653 .ctl_name = KERN_OVERFLOWUID,
654 .procname = "overflowuid",
655 .data = &overflowuid,
656 .maxlen = sizeof(int),
657 .mode = 0644,
658 .proc_handler = &proc_dointvec_minmax,
659 .strategy = &sysctl_intvec,
660 .extra1 = &minolduid,
661 .extra2 = &maxolduid,
664 .ctl_name = KERN_OVERFLOWGID,
665 .procname = "overflowgid",
666 .data = &overflowgid,
667 .maxlen = sizeof(int),
668 .mode = 0644,
669 .proc_handler = &proc_dointvec_minmax,
670 .strategy = &sysctl_intvec,
671 .extra1 = &minolduid,
672 .extra2 = &maxolduid,
674 #ifdef CONFIG_S390
675 #ifdef CONFIG_MATHEMU
677 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
678 .procname = "ieee_emulation_warnings",
679 .data = &sysctl_ieee_emulation_warnings,
680 .maxlen = sizeof(int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
684 #endif
686 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
687 .procname = "userprocess_debug",
688 .data = &sysctl_userprocess_debug,
689 .maxlen = sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
693 #endif
695 .ctl_name = KERN_PIDMAX,
696 .procname = "pid_max",
697 .data = &pid_max,
698 .maxlen = sizeof (int),
699 .mode = 0644,
700 .proc_handler = &proc_dointvec_minmax,
701 .strategy = sysctl_intvec,
702 .extra1 = &pid_max_min,
703 .extra2 = &pid_max_max,
706 .ctl_name = KERN_PANIC_ON_OOPS,
707 .procname = "panic_on_oops",
708 .data = &panic_on_oops,
709 .maxlen = sizeof(int),
710 .mode = 0644,
711 .proc_handler = &proc_dointvec,
713 #if defined CONFIG_PRINTK
715 .ctl_name = KERN_PRINTK,
716 .procname = "printk",
717 .data = &console_loglevel,
718 .maxlen = 4*sizeof(int),
719 .mode = 0644,
720 .proc_handler = &proc_dointvec,
723 .ctl_name = KERN_PRINTK_RATELIMIT,
724 .procname = "printk_ratelimit",
725 .data = &printk_ratelimit_state.interval,
726 .maxlen = sizeof(int),
727 .mode = 0644,
728 .proc_handler = &proc_dointvec_jiffies,
729 .strategy = &sysctl_jiffies,
732 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
733 .procname = "printk_ratelimit_burst",
734 .data = &printk_ratelimit_state.burst,
735 .maxlen = sizeof(int),
736 .mode = 0644,
737 .proc_handler = &proc_dointvec,
740 .ctl_name = CTL_UNNUMBERED,
741 .procname = "printk_delay",
742 .data = &printk_delay_msec,
743 .maxlen = sizeof(int),
744 .mode = 0644,
745 .proc_handler = &proc_dointvec_minmax,
746 .strategy = &sysctl_intvec,
747 .extra1 = &zero,
748 .extra2 = &ten_thousand,
750 #endif
752 .ctl_name = KERN_NGROUPS_MAX,
753 .procname = "ngroups_max",
754 .data = &ngroups_max,
755 .maxlen = sizeof (int),
756 .mode = 0444,
757 .proc_handler = &proc_dointvec,
759 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
761 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
762 .procname = "unknown_nmi_panic",
763 .data = &unknown_nmi_panic,
764 .maxlen = sizeof (int),
765 .mode = 0644,
766 .proc_handler = &proc_dointvec,
769 .procname = "nmi_watchdog",
770 .data = &nmi_watchdog_enabled,
771 .maxlen = sizeof (int),
772 .mode = 0644,
773 .proc_handler = &proc_nmi_enabled,
775 #endif
776 #if defined(CONFIG_X86)
778 .ctl_name = KERN_PANIC_ON_NMI,
779 .procname = "panic_on_unrecovered_nmi",
780 .data = &panic_on_unrecovered_nmi,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec,
786 .ctl_name = CTL_UNNUMBERED,
787 .procname = "panic_on_io_nmi",
788 .data = &panic_on_io_nmi,
789 .maxlen = sizeof(int),
790 .mode = 0644,
791 .proc_handler = &proc_dointvec,
794 .ctl_name = KERN_BOOTLOADER_TYPE,
795 .procname = "bootloader_type",
796 .data = &bootloader_type,
797 .maxlen = sizeof (int),
798 .mode = 0444,
799 .proc_handler = &proc_dointvec,
802 .ctl_name = CTL_UNNUMBERED,
803 .procname = "bootloader_version",
804 .data = &bootloader_version,
805 .maxlen = sizeof (int),
806 .mode = 0444,
807 .proc_handler = &proc_dointvec,
810 .ctl_name = CTL_UNNUMBERED,
811 .procname = "kstack_depth_to_print",
812 .data = &kstack_depth_to_print,
813 .maxlen = sizeof(int),
814 .mode = 0644,
815 .proc_handler = &proc_dointvec,
818 .ctl_name = CTL_UNNUMBERED,
819 .procname = "io_delay_type",
820 .data = &io_delay_type,
821 .maxlen = sizeof(int),
822 .mode = 0644,
823 .proc_handler = &proc_dointvec,
825 #endif
826 #if defined(CONFIG_MMU)
828 .ctl_name = KERN_RANDOMIZE,
829 .procname = "randomize_va_space",
830 .data = &randomize_va_space,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec,
835 #endif
836 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
838 .ctl_name = KERN_SPIN_RETRY,
839 .procname = "spin_retry",
840 .data = &spin_retry,
841 .maxlen = sizeof (int),
842 .mode = 0644,
843 .proc_handler = &proc_dointvec,
845 #endif
846 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
848 .procname = "acpi_video_flags",
849 .data = &acpi_realmode_flags,
850 .maxlen = sizeof (unsigned long),
851 .mode = 0644,
852 .proc_handler = &proc_doulongvec_minmax,
854 #endif
855 #ifdef CONFIG_IA64
857 .ctl_name = KERN_IA64_UNALIGNED,
858 .procname = "ignore-unaligned-usertrap",
859 .data = &no_unaligned_warning,
860 .maxlen = sizeof (int),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec,
865 .ctl_name = CTL_UNNUMBERED,
866 .procname = "unaligned-dump-stack",
867 .data = &unaligned_dump_stack,
868 .maxlen = sizeof (int),
869 .mode = 0644,
870 .proc_handler = &proc_dointvec,
872 #endif
873 #ifdef CONFIG_DETECT_SOFTLOCKUP
875 .ctl_name = CTL_UNNUMBERED,
876 .procname = "softlockup_panic",
877 .data = &softlockup_panic,
878 .maxlen = sizeof(int),
879 .mode = 0644,
880 .proc_handler = &proc_dointvec_minmax,
881 .strategy = &sysctl_intvec,
882 .extra1 = &zero,
883 .extra2 = &one,
886 .ctl_name = CTL_UNNUMBERED,
887 .procname = "softlockup_thresh",
888 .data = &softlockup_thresh,
889 .maxlen = sizeof(int),
890 .mode = 0644,
891 .proc_handler = &proc_dosoftlockup_thresh,
892 .strategy = &sysctl_intvec,
893 .extra1 = &neg_one,
894 .extra2 = &sixty,
896 #endif
897 #ifdef CONFIG_DETECT_HUNG_TASK
899 .ctl_name = CTL_UNNUMBERED,
900 .procname = "hung_task_panic",
901 .data = &sysctl_hung_task_panic,
902 .maxlen = sizeof(int),
903 .mode = 0644,
904 .proc_handler = &proc_dointvec_minmax,
905 .strategy = &sysctl_intvec,
906 .extra1 = &zero,
907 .extra2 = &one,
910 .ctl_name = CTL_UNNUMBERED,
911 .procname = "hung_task_check_count",
912 .data = &sysctl_hung_task_check_count,
913 .maxlen = sizeof(unsigned long),
914 .mode = 0644,
915 .proc_handler = &proc_doulongvec_minmax,
916 .strategy = &sysctl_intvec,
919 .ctl_name = CTL_UNNUMBERED,
920 .procname = "hung_task_timeout_secs",
921 .data = &sysctl_hung_task_timeout_secs,
922 .maxlen = sizeof(unsigned long),
923 .mode = 0644,
924 .proc_handler = &proc_dohung_task_timeout_secs,
925 .strategy = &sysctl_intvec,
928 .ctl_name = CTL_UNNUMBERED,
929 .procname = "hung_task_warnings",
930 .data = &sysctl_hung_task_warnings,
931 .maxlen = sizeof(unsigned long),
932 .mode = 0644,
933 .proc_handler = &proc_doulongvec_minmax,
934 .strategy = &sysctl_intvec,
936 #endif
937 #ifdef CONFIG_COMPAT
939 .ctl_name = KERN_COMPAT_LOG,
940 .procname = "compat-log",
941 .data = &compat_log,
942 .maxlen = sizeof (int),
943 .mode = 0644,
944 .proc_handler = &proc_dointvec,
946 #endif
947 #ifdef CONFIG_RT_MUTEXES
949 .ctl_name = KERN_MAX_LOCK_DEPTH,
950 .procname = "max_lock_depth",
951 .data = &max_lock_depth,
952 .maxlen = sizeof(int),
953 .mode = 0644,
954 .proc_handler = &proc_dointvec,
956 #endif
958 .ctl_name = CTL_UNNUMBERED,
959 .procname = "poweroff_cmd",
960 .data = &poweroff_cmd,
961 .maxlen = POWEROFF_CMD_PATH_LEN,
962 .mode = 0644,
963 .proc_handler = &proc_dostring,
964 .strategy = &sysctl_string,
966 #ifdef CONFIG_KEYS
968 .ctl_name = CTL_UNNUMBERED,
969 .procname = "keys",
970 .mode = 0555,
971 .child = key_sysctls,
973 #endif
974 #ifdef CONFIG_RCU_TORTURE_TEST
976 .ctl_name = CTL_UNNUMBERED,
977 .procname = "rcutorture_runnable",
978 .data = &rcutorture_runnable,
979 .maxlen = sizeof(int),
980 .mode = 0644,
981 .proc_handler = &proc_dointvec,
983 #endif
984 #ifdef CONFIG_SLOW_WORK
986 .ctl_name = CTL_UNNUMBERED,
987 .procname = "slow-work",
988 .mode = 0555,
989 .child = slow_work_sysctls,
991 #endif
992 #ifdef CONFIG_PERF_EVENTS
994 .ctl_name = CTL_UNNUMBERED,
995 .procname = "perf_event_paranoid",
996 .data = &sysctl_perf_event_paranoid,
997 .maxlen = sizeof(sysctl_perf_event_paranoid),
998 .mode = 0644,
999 .proc_handler = &proc_dointvec,
1002 .ctl_name = CTL_UNNUMBERED,
1003 .procname = "perf_event_mlock_kb",
1004 .data = &sysctl_perf_event_mlock,
1005 .maxlen = sizeof(sysctl_perf_event_mlock),
1006 .mode = 0644,
1007 .proc_handler = &proc_dointvec,
1010 .ctl_name = CTL_UNNUMBERED,
1011 .procname = "perf_event_max_sample_rate",
1012 .data = &sysctl_perf_event_sample_rate,
1013 .maxlen = sizeof(sysctl_perf_event_sample_rate),
1014 .mode = 0644,
1015 .proc_handler = &proc_dointvec,
1017 #endif
1018 #ifdef CONFIG_KMEMCHECK
1020 .ctl_name = CTL_UNNUMBERED,
1021 .procname = "kmemcheck",
1022 .data = &kmemcheck_enabled,
1023 .maxlen = sizeof(int),
1024 .mode = 0644,
1025 .proc_handler = &proc_dointvec,
1027 #endif
1028 #ifdef CONFIG_BLOCK
1030 .ctl_name = CTL_UNNUMBERED,
1031 .procname = "blk_iopoll",
1032 .data = &blk_iopoll_enabled,
1033 .maxlen = sizeof(int),
1034 .mode = 0644,
1035 .proc_handler = &proc_dointvec,
1037 #endif
1039 * NOTE: do not add new entries to this table unless you have read
1040 * Documentation/sysctl/ctl_unnumbered.txt
1042 { .ctl_name = 0 }
1045 static struct ctl_table vm_table[] = {
1047 .ctl_name = VM_OVERCOMMIT_MEMORY,
1048 .procname = "overcommit_memory",
1049 .data = &sysctl_overcommit_memory,
1050 .maxlen = sizeof(sysctl_overcommit_memory),
1051 .mode = 0644,
1052 .proc_handler = &proc_dointvec,
1055 .ctl_name = VM_PANIC_ON_OOM,
1056 .procname = "panic_on_oom",
1057 .data = &sysctl_panic_on_oom,
1058 .maxlen = sizeof(sysctl_panic_on_oom),
1059 .mode = 0644,
1060 .proc_handler = &proc_dointvec,
1063 .ctl_name = CTL_UNNUMBERED,
1064 .procname = "oom_kill_allocating_task",
1065 .data = &sysctl_oom_kill_allocating_task,
1066 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
1067 .mode = 0644,
1068 .proc_handler = &proc_dointvec,
1071 .ctl_name = CTL_UNNUMBERED,
1072 .procname = "oom_dump_tasks",
1073 .data = &sysctl_oom_dump_tasks,
1074 .maxlen = sizeof(sysctl_oom_dump_tasks),
1075 .mode = 0644,
1076 .proc_handler = &proc_dointvec,
1079 .ctl_name = VM_OVERCOMMIT_RATIO,
1080 .procname = "overcommit_ratio",
1081 .data = &sysctl_overcommit_ratio,
1082 .maxlen = sizeof(sysctl_overcommit_ratio),
1083 .mode = 0644,
1084 .proc_handler = &proc_dointvec,
1087 .ctl_name = VM_PAGE_CLUSTER,
1088 .procname = "page-cluster",
1089 .data = &page_cluster,
1090 .maxlen = sizeof(int),
1091 .mode = 0644,
1092 .proc_handler = &proc_dointvec,
1095 .ctl_name = VM_DIRTY_BACKGROUND,
1096 .procname = "dirty_background_ratio",
1097 .data = &dirty_background_ratio,
1098 .maxlen = sizeof(dirty_background_ratio),
1099 .mode = 0644,
1100 .proc_handler = &dirty_background_ratio_handler,
1101 .strategy = &sysctl_intvec,
1102 .extra1 = &zero,
1103 .extra2 = &one_hundred,
1106 .ctl_name = CTL_UNNUMBERED,
1107 .procname = "dirty_background_bytes",
1108 .data = &dirty_background_bytes,
1109 .maxlen = sizeof(dirty_background_bytes),
1110 .mode = 0644,
1111 .proc_handler = &dirty_background_bytes_handler,
1112 .strategy = &sysctl_intvec,
1113 .extra1 = &one_ul,
1116 .ctl_name = VM_DIRTY_RATIO,
1117 .procname = "dirty_ratio",
1118 .data = &vm_dirty_ratio,
1119 .maxlen = sizeof(vm_dirty_ratio),
1120 .mode = 0644,
1121 .proc_handler = &dirty_ratio_handler,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &zero,
1124 .extra2 = &one_hundred,
1127 .ctl_name = CTL_UNNUMBERED,
1128 .procname = "dirty_bytes",
1129 .data = &vm_dirty_bytes,
1130 .maxlen = sizeof(vm_dirty_bytes),
1131 .mode = 0644,
1132 .proc_handler = &dirty_bytes_handler,
1133 .strategy = &sysctl_intvec,
1134 .extra1 = &dirty_bytes_min,
1137 .procname = "dirty_writeback_centisecs",
1138 .data = &dirty_writeback_interval,
1139 .maxlen = sizeof(dirty_writeback_interval),
1140 .mode = 0644,
1141 .proc_handler = &dirty_writeback_centisecs_handler,
1144 .procname = "dirty_expire_centisecs",
1145 .data = &dirty_expire_interval,
1146 .maxlen = sizeof(dirty_expire_interval),
1147 .mode = 0644,
1148 .proc_handler = &proc_dointvec,
1151 .ctl_name = VM_NR_PDFLUSH_THREADS,
1152 .procname = "nr_pdflush_threads",
1153 .data = &nr_pdflush_threads,
1154 .maxlen = sizeof nr_pdflush_threads,
1155 .mode = 0444 /* read-only*/,
1156 .proc_handler = &proc_dointvec,
1159 .ctl_name = VM_SWAPPINESS,
1160 .procname = "swappiness",
1161 .data = &vm_swappiness,
1162 .maxlen = sizeof(vm_swappiness),
1163 .mode = 0644,
1164 .proc_handler = &proc_dointvec_minmax,
1165 .strategy = &sysctl_intvec,
1166 .extra1 = &zero,
1167 .extra2 = &one_hundred,
1169 #ifdef CONFIG_HUGETLB_PAGE
1171 .procname = "nr_hugepages",
1172 .data = NULL,
1173 .maxlen = sizeof(unsigned long),
1174 .mode = 0644,
1175 .proc_handler = &hugetlb_sysctl_handler,
1176 .extra1 = (void *)&hugetlb_zero,
1177 .extra2 = (void *)&hugetlb_infinity,
1179 #ifdef CONFIG_NUMA
1181 .ctl_name = CTL_UNNUMBERED,
1182 .procname = "nr_hugepages_mempolicy",
1183 .data = NULL,
1184 .maxlen = sizeof(unsigned long),
1185 .mode = 0644,
1186 .proc_handler = &hugetlb_mempolicy_sysctl_handler,
1187 .extra1 = (void *)&hugetlb_zero,
1188 .extra2 = (void *)&hugetlb_infinity,
1190 #endif
1192 .ctl_name = VM_HUGETLB_GROUP,
1193 .procname = "hugetlb_shm_group",
1194 .data = &sysctl_hugetlb_shm_group,
1195 .maxlen = sizeof(gid_t),
1196 .mode = 0644,
1197 .proc_handler = &proc_dointvec,
1200 .ctl_name = CTL_UNNUMBERED,
1201 .procname = "hugepages_treat_as_movable",
1202 .data = &hugepages_treat_as_movable,
1203 .maxlen = sizeof(int),
1204 .mode = 0644,
1205 .proc_handler = &hugetlb_treat_movable_handler,
1208 .ctl_name = CTL_UNNUMBERED,
1209 .procname = "nr_overcommit_hugepages",
1210 .data = NULL,
1211 .maxlen = sizeof(unsigned long),
1212 .mode = 0644,
1213 .proc_handler = &hugetlb_overcommit_handler,
1214 .extra1 = (void *)&hugetlb_zero,
1215 .extra2 = (void *)&hugetlb_infinity,
1217 #endif
1219 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1220 .procname = "lowmem_reserve_ratio",
1221 .data = &sysctl_lowmem_reserve_ratio,
1222 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1223 .mode = 0644,
1224 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1225 .strategy = &sysctl_intvec,
1228 .ctl_name = VM_DROP_PAGECACHE,
1229 .procname = "drop_caches",
1230 .data = &sysctl_drop_caches,
1231 .maxlen = sizeof(int),
1232 .mode = 0644,
1233 .proc_handler = drop_caches_sysctl_handler,
1234 .strategy = &sysctl_intvec,
1237 .ctl_name = VM_MIN_FREE_KBYTES,
1238 .procname = "min_free_kbytes",
1239 .data = &min_free_kbytes,
1240 .maxlen = sizeof(min_free_kbytes),
1241 .mode = 0644,
1242 .proc_handler = &min_free_kbytes_sysctl_handler,
1243 .strategy = &sysctl_intvec,
1244 .extra1 = &zero,
1247 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1248 .procname = "percpu_pagelist_fraction",
1249 .data = &percpu_pagelist_fraction,
1250 .maxlen = sizeof(percpu_pagelist_fraction),
1251 .mode = 0644,
1252 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1253 .strategy = &sysctl_intvec,
1254 .extra1 = &min_percpu_pagelist_fract,
1256 #ifdef CONFIG_MMU
1258 .ctl_name = VM_MAX_MAP_COUNT,
1259 .procname = "max_map_count",
1260 .data = &sysctl_max_map_count,
1261 .maxlen = sizeof(sysctl_max_map_count),
1262 .mode = 0644,
1263 .proc_handler = &proc_dointvec
1265 #else
1267 .ctl_name = CTL_UNNUMBERED,
1268 .procname = "nr_trim_pages",
1269 .data = &sysctl_nr_trim_pages,
1270 .maxlen = sizeof(sysctl_nr_trim_pages),
1271 .mode = 0644,
1272 .proc_handler = &proc_dointvec_minmax,
1273 .strategy = &sysctl_intvec,
1274 .extra1 = &zero,
1276 #endif
1278 .ctl_name = VM_LAPTOP_MODE,
1279 .procname = "laptop_mode",
1280 .data = &laptop_mode,
1281 .maxlen = sizeof(laptop_mode),
1282 .mode = 0644,
1283 .proc_handler = &proc_dointvec_jiffies,
1284 .strategy = &sysctl_jiffies,
1287 .ctl_name = VM_BLOCK_DUMP,
1288 .procname = "block_dump",
1289 .data = &block_dump,
1290 .maxlen = sizeof(block_dump),
1291 .mode = 0644,
1292 .proc_handler = &proc_dointvec,
1293 .strategy = &sysctl_intvec,
1294 .extra1 = &zero,
1297 .ctl_name = VM_VFS_CACHE_PRESSURE,
1298 .procname = "vfs_cache_pressure",
1299 .data = &sysctl_vfs_cache_pressure,
1300 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1301 .mode = 0644,
1302 .proc_handler = &proc_dointvec,
1303 .strategy = &sysctl_intvec,
1304 .extra1 = &zero,
1306 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1308 .ctl_name = VM_LEGACY_VA_LAYOUT,
1309 .procname = "legacy_va_layout",
1310 .data = &sysctl_legacy_va_layout,
1311 .maxlen = sizeof(sysctl_legacy_va_layout),
1312 .mode = 0644,
1313 .proc_handler = &proc_dointvec,
1314 .strategy = &sysctl_intvec,
1315 .extra1 = &zero,
1317 #endif
1318 #ifdef CONFIG_NUMA
1320 .ctl_name = VM_ZONE_RECLAIM_MODE,
1321 .procname = "zone_reclaim_mode",
1322 .data = &zone_reclaim_mode,
1323 .maxlen = sizeof(zone_reclaim_mode),
1324 .mode = 0644,
1325 .proc_handler = &proc_dointvec,
1326 .strategy = &sysctl_intvec,
1327 .extra1 = &zero,
1330 .ctl_name = VM_MIN_UNMAPPED,
1331 .procname = "min_unmapped_ratio",
1332 .data = &sysctl_min_unmapped_ratio,
1333 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1334 .mode = 0644,
1335 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1336 .strategy = &sysctl_intvec,
1337 .extra1 = &zero,
1338 .extra2 = &one_hundred,
1341 .ctl_name = VM_MIN_SLAB,
1342 .procname = "min_slab_ratio",
1343 .data = &sysctl_min_slab_ratio,
1344 .maxlen = sizeof(sysctl_min_slab_ratio),
1345 .mode = 0644,
1346 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1347 .strategy = &sysctl_intvec,
1348 .extra1 = &zero,
1349 .extra2 = &one_hundred,
1351 #endif
1352 #ifdef CONFIG_SMP
1354 .ctl_name = CTL_UNNUMBERED,
1355 .procname = "stat_interval",
1356 .data = &sysctl_stat_interval,
1357 .maxlen = sizeof(sysctl_stat_interval),
1358 .mode = 0644,
1359 .proc_handler = &proc_dointvec_jiffies,
1360 .strategy = &sysctl_jiffies,
1362 #endif
1364 .ctl_name = CTL_UNNUMBERED,
1365 .procname = "mmap_min_addr",
1366 .data = &dac_mmap_min_addr,
1367 .maxlen = sizeof(unsigned long),
1368 .mode = 0644,
1369 .proc_handler = &mmap_min_addr_handler,
1371 #ifdef CONFIG_NUMA
1373 .ctl_name = CTL_UNNUMBERED,
1374 .procname = "numa_zonelist_order",
1375 .data = &numa_zonelist_order,
1376 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1377 .mode = 0644,
1378 .proc_handler = &numa_zonelist_order_handler,
1379 .strategy = &sysctl_string,
1381 #endif
1382 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1383 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1385 .ctl_name = VM_VDSO_ENABLED,
1386 .procname = "vdso_enabled",
1387 .data = &vdso_enabled,
1388 .maxlen = sizeof(vdso_enabled),
1389 .mode = 0644,
1390 .proc_handler = &proc_dointvec,
1391 .strategy = &sysctl_intvec,
1392 .extra1 = &zero,
1394 #endif
1395 #ifdef CONFIG_HIGHMEM
1397 .ctl_name = CTL_UNNUMBERED,
1398 .procname = "highmem_is_dirtyable",
1399 .data = &vm_highmem_is_dirtyable,
1400 .maxlen = sizeof(vm_highmem_is_dirtyable),
1401 .mode = 0644,
1402 .proc_handler = &proc_dointvec_minmax,
1403 .strategy = &sysctl_intvec,
1404 .extra1 = &zero,
1405 .extra2 = &one,
1407 #endif
1409 .ctl_name = CTL_UNNUMBERED,
1410 .procname = "scan_unevictable_pages",
1411 .data = &scan_unevictable_pages,
1412 .maxlen = sizeof(scan_unevictable_pages),
1413 .mode = 0644,
1414 .proc_handler = &scan_unevictable_handler,
1416 #ifdef CONFIG_MEMORY_FAILURE
1418 .ctl_name = CTL_UNNUMBERED,
1419 .procname = "memory_failure_early_kill",
1420 .data = &sysctl_memory_failure_early_kill,
1421 .maxlen = sizeof(sysctl_memory_failure_early_kill),
1422 .mode = 0644,
1423 .proc_handler = &proc_dointvec_minmax,
1424 .strategy = &sysctl_intvec,
1425 .extra1 = &zero,
1426 .extra2 = &one,
1429 .ctl_name = CTL_UNNUMBERED,
1430 .procname = "memory_failure_recovery",
1431 .data = &sysctl_memory_failure_recovery,
1432 .maxlen = sizeof(sysctl_memory_failure_recovery),
1433 .mode = 0644,
1434 .proc_handler = &proc_dointvec_minmax,
1435 .strategy = &sysctl_intvec,
1436 .extra1 = &zero,
1437 .extra2 = &one,
1439 #endif
1442 * NOTE: do not add new entries to this table unless you have read
1443 * Documentation/sysctl/ctl_unnumbered.txt
1445 { .ctl_name = 0 }
1448 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1449 static struct ctl_table binfmt_misc_table[] = {
1450 { .ctl_name = 0 }
1452 #endif
1454 static struct ctl_table fs_table[] = {
1456 .ctl_name = FS_NRINODE,
1457 .procname = "inode-nr",
1458 .data = &inodes_stat,
1459 .maxlen = 2*sizeof(int),
1460 .mode = 0444,
1461 .proc_handler = &proc_dointvec,
1464 .ctl_name = FS_STATINODE,
1465 .procname = "inode-state",
1466 .data = &inodes_stat,
1467 .maxlen = 7*sizeof(int),
1468 .mode = 0444,
1469 .proc_handler = &proc_dointvec,
1472 .procname = "file-nr",
1473 .data = &files_stat,
1474 .maxlen = 3*sizeof(int),
1475 .mode = 0444,
1476 .proc_handler = &proc_nr_files,
1479 .ctl_name = FS_MAXFILE,
1480 .procname = "file-max",
1481 .data = &files_stat.max_files,
1482 .maxlen = sizeof(int),
1483 .mode = 0644,
1484 .proc_handler = &proc_dointvec,
1487 .ctl_name = CTL_UNNUMBERED,
1488 .procname = "nr_open",
1489 .data = &sysctl_nr_open,
1490 .maxlen = sizeof(int),
1491 .mode = 0644,
1492 .proc_handler = &proc_dointvec_minmax,
1493 .extra1 = &sysctl_nr_open_min,
1494 .extra2 = &sysctl_nr_open_max,
1497 .ctl_name = FS_DENTRY,
1498 .procname = "dentry-state",
1499 .data = &dentry_stat,
1500 .maxlen = 6*sizeof(int),
1501 .mode = 0444,
1502 .proc_handler = &proc_dointvec,
1505 .ctl_name = FS_OVERFLOWUID,
1506 .procname = "overflowuid",
1507 .data = &fs_overflowuid,
1508 .maxlen = sizeof(int),
1509 .mode = 0644,
1510 .proc_handler = &proc_dointvec_minmax,
1511 .strategy = &sysctl_intvec,
1512 .extra1 = &minolduid,
1513 .extra2 = &maxolduid,
1516 .ctl_name = FS_OVERFLOWGID,
1517 .procname = "overflowgid",
1518 .data = &fs_overflowgid,
1519 .maxlen = sizeof(int),
1520 .mode = 0644,
1521 .proc_handler = &proc_dointvec_minmax,
1522 .strategy = &sysctl_intvec,
1523 .extra1 = &minolduid,
1524 .extra2 = &maxolduid,
1526 #ifdef CONFIG_FILE_LOCKING
1528 .ctl_name = FS_LEASES,
1529 .procname = "leases-enable",
1530 .data = &leases_enable,
1531 .maxlen = sizeof(int),
1532 .mode = 0644,
1533 .proc_handler = &proc_dointvec,
1535 #endif
1536 #ifdef CONFIG_DNOTIFY
1538 .ctl_name = FS_DIR_NOTIFY,
1539 .procname = "dir-notify-enable",
1540 .data = &dir_notify_enable,
1541 .maxlen = sizeof(int),
1542 .mode = 0644,
1543 .proc_handler = &proc_dointvec,
1545 #endif
1546 #ifdef CONFIG_MMU
1547 #ifdef CONFIG_FILE_LOCKING
1549 .ctl_name = FS_LEASE_TIME,
1550 .procname = "lease-break-time",
1551 .data = &lease_break_time,
1552 .maxlen = sizeof(int),
1553 .mode = 0644,
1554 .proc_handler = &proc_dointvec,
1556 #endif
1557 #ifdef CONFIG_AIO
1559 .procname = "aio-nr",
1560 .data = &aio_nr,
1561 .maxlen = sizeof(aio_nr),
1562 .mode = 0444,
1563 .proc_handler = &proc_doulongvec_minmax,
1566 .procname = "aio-max-nr",
1567 .data = &aio_max_nr,
1568 .maxlen = sizeof(aio_max_nr),
1569 .mode = 0644,
1570 .proc_handler = &proc_doulongvec_minmax,
1572 #endif /* CONFIG_AIO */
1573 #ifdef CONFIG_INOTIFY_USER
1575 .ctl_name = FS_INOTIFY,
1576 .procname = "inotify",
1577 .mode = 0555,
1578 .child = inotify_table,
1580 #endif
1581 #ifdef CONFIG_EPOLL
1583 .procname = "epoll",
1584 .mode = 0555,
1585 .child = epoll_table,
1587 #endif
1588 #endif
1590 .ctl_name = KERN_SETUID_DUMPABLE,
1591 .procname = "suid_dumpable",
1592 .data = &suid_dumpable,
1593 .maxlen = sizeof(int),
1594 .mode = 0644,
1595 .proc_handler = &proc_dointvec_minmax,
1596 .strategy = &sysctl_intvec,
1597 .extra1 = &zero,
1598 .extra2 = &two,
1600 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1602 .ctl_name = CTL_UNNUMBERED,
1603 .procname = "binfmt_misc",
1604 .mode = 0555,
1605 .child = binfmt_misc_table,
1607 #endif
1609 * NOTE: do not add new entries to this table unless you have read
1610 * Documentation/sysctl/ctl_unnumbered.txt
1612 { .ctl_name = 0 }
1615 static struct ctl_table debug_table[] = {
1616 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1618 .ctl_name = CTL_UNNUMBERED,
1619 .procname = "exception-trace",
1620 .data = &show_unhandled_signals,
1621 .maxlen = sizeof(int),
1622 .mode = 0644,
1623 .proc_handler = proc_dointvec
1625 #endif
1626 { .ctl_name = 0 }
1629 static struct ctl_table dev_table[] = {
1630 { .ctl_name = 0 }
1633 static DEFINE_SPINLOCK(sysctl_lock);
1635 /* called under sysctl_lock */
1636 static int use_table(struct ctl_table_header *p)
1638 if (unlikely(p->unregistering))
1639 return 0;
1640 p->used++;
1641 return 1;
1644 /* called under sysctl_lock */
1645 static void unuse_table(struct ctl_table_header *p)
1647 if (!--p->used)
1648 if (unlikely(p->unregistering))
1649 complete(p->unregistering);
1652 /* called under sysctl_lock, will reacquire if has to wait */
1653 static void start_unregistering(struct ctl_table_header *p)
1656 * if p->used is 0, nobody will ever touch that entry again;
1657 * we'll eliminate all paths to it before dropping sysctl_lock
1659 if (unlikely(p->used)) {
1660 struct completion wait;
1661 init_completion(&wait);
1662 p->unregistering = &wait;
1663 spin_unlock(&sysctl_lock);
1664 wait_for_completion(&wait);
1665 spin_lock(&sysctl_lock);
1666 } else {
1667 /* anything non-NULL; we'll never dereference it */
1668 p->unregistering = ERR_PTR(-EINVAL);
1671 * do not remove from the list until nobody holds it; walking the
1672 * list in do_sysctl() relies on that.
1674 list_del_init(&p->ctl_entry);
1677 void sysctl_head_get(struct ctl_table_header *head)
1679 spin_lock(&sysctl_lock);
1680 head->count++;
1681 spin_unlock(&sysctl_lock);
1684 void sysctl_head_put(struct ctl_table_header *head)
1686 spin_lock(&sysctl_lock);
1687 if (!--head->count)
1688 kfree(head);
1689 spin_unlock(&sysctl_lock);
1692 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1694 if (!head)
1695 BUG();
1696 spin_lock(&sysctl_lock);
1697 if (!use_table(head))
1698 head = ERR_PTR(-ENOENT);
1699 spin_unlock(&sysctl_lock);
1700 return head;
1703 void sysctl_head_finish(struct ctl_table_header *head)
1705 if (!head)
1706 return;
1707 spin_lock(&sysctl_lock);
1708 unuse_table(head);
1709 spin_unlock(&sysctl_lock);
1712 static struct ctl_table_set *
1713 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1715 struct ctl_table_set *set = &root->default_set;
1716 if (root->lookup)
1717 set = root->lookup(root, namespaces);
1718 return set;
1721 static struct list_head *
1722 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1724 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1725 return &set->list;
1728 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1729 struct ctl_table_header *prev)
1731 struct ctl_table_root *root;
1732 struct list_head *header_list;
1733 struct ctl_table_header *head;
1734 struct list_head *tmp;
1736 spin_lock(&sysctl_lock);
1737 if (prev) {
1738 head = prev;
1739 tmp = &prev->ctl_entry;
1740 unuse_table(prev);
1741 goto next;
1743 tmp = &root_table_header.ctl_entry;
1744 for (;;) {
1745 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1747 if (!use_table(head))
1748 goto next;
1749 spin_unlock(&sysctl_lock);
1750 return head;
1751 next:
1752 root = head->root;
1753 tmp = tmp->next;
1754 header_list = lookup_header_list(root, namespaces);
1755 if (tmp != header_list)
1756 continue;
1758 do {
1759 root = list_entry(root->root_list.next,
1760 struct ctl_table_root, root_list);
1761 if (root == &sysctl_table_root)
1762 goto out;
1763 header_list = lookup_header_list(root, namespaces);
1764 } while (list_empty(header_list));
1765 tmp = header_list->next;
1767 out:
1768 spin_unlock(&sysctl_lock);
1769 return NULL;
1772 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1774 return __sysctl_head_next(current->nsproxy, prev);
1777 void register_sysctl_root(struct ctl_table_root *root)
1779 spin_lock(&sysctl_lock);
1780 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1781 spin_unlock(&sysctl_lock);
1784 #ifdef CONFIG_SYSCTL_SYSCALL
1785 /* Perform the actual read/write of a sysctl table entry. */
1786 static int do_sysctl_strategy(struct ctl_table_root *root,
1787 struct ctl_table *table,
1788 void __user *oldval, size_t __user *oldlenp,
1789 void __user *newval, size_t newlen)
1791 int op = 0, rc;
1793 if (oldval)
1794 op |= MAY_READ;
1795 if (newval)
1796 op |= MAY_WRITE;
1797 if (sysctl_perm(root, table, op))
1798 return -EPERM;
1800 if (table->strategy) {
1801 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1802 if (rc < 0)
1803 return rc;
1804 if (rc > 0)
1805 return 0;
1808 /* If there is no strategy routine, or if the strategy returns
1809 * zero, proceed with automatic r/w */
1810 if (table->data && table->maxlen) {
1811 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1812 if (rc < 0)
1813 return rc;
1815 return 0;
1818 static int parse_table(int __user *name, int nlen,
1819 void __user *oldval, size_t __user *oldlenp,
1820 void __user *newval, size_t newlen,
1821 struct ctl_table_root *root,
1822 struct ctl_table *table)
1824 int n;
1825 repeat:
1826 if (!nlen)
1827 return -ENOTDIR;
1828 if (get_user(n, name))
1829 return -EFAULT;
1830 for ( ; table->ctl_name || table->procname; table++) {
1831 if (!table->ctl_name)
1832 continue;
1833 if (n == table->ctl_name) {
1834 int error;
1835 if (table->child) {
1836 if (sysctl_perm(root, table, MAY_EXEC))
1837 return -EPERM;
1838 name++;
1839 nlen--;
1840 table = table->child;
1841 goto repeat;
1843 error = do_sysctl_strategy(root, table,
1844 oldval, oldlenp,
1845 newval, newlen);
1846 return error;
1849 return -ENOTDIR;
1852 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1853 void __user *newval, size_t newlen)
1855 struct ctl_table_header *head;
1856 int error = -ENOTDIR;
1858 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1859 return -ENOTDIR;
1860 if (oldval) {
1861 int old_len;
1862 if (!oldlenp || get_user(old_len, oldlenp))
1863 return -EFAULT;
1866 for (head = sysctl_head_next(NULL); head;
1867 head = sysctl_head_next(head)) {
1868 error = parse_table(name, nlen, oldval, oldlenp,
1869 newval, newlen,
1870 head->root, head->ctl_table);
1871 if (error != -ENOTDIR) {
1872 sysctl_head_finish(head);
1873 break;
1876 return error;
1879 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
1881 struct __sysctl_args tmp;
1882 int error;
1884 if (copy_from_user(&tmp, args, sizeof(tmp)))
1885 return -EFAULT;
1887 error = deprecated_sysctl_warning(&tmp);
1888 if (error)
1889 goto out;
1891 lock_kernel();
1892 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1893 tmp.newval, tmp.newlen);
1894 unlock_kernel();
1895 out:
1896 return error;
1898 #endif /* CONFIG_SYSCTL_SYSCALL */
1901 * sysctl_perm does NOT grant the superuser all rights automatically, because
1902 * some sysctl variables are readonly even to root.
1905 static int test_perm(int mode, int op)
1907 if (!current_euid())
1908 mode >>= 6;
1909 else if (in_egroup_p(0))
1910 mode >>= 3;
1911 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1912 return 0;
1913 return -EACCES;
1916 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1918 int error;
1919 int mode;
1921 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1922 if (error)
1923 return error;
1925 if (root->permissions)
1926 mode = root->permissions(root, current->nsproxy, table);
1927 else
1928 mode = table->mode;
1930 return test_perm(mode, op);
1933 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1935 for (; table->ctl_name || table->procname; table++) {
1936 table->parent = parent;
1937 if (table->child)
1938 sysctl_set_parent(table, table->child);
1942 static __init int sysctl_init(void)
1944 sysctl_set_parent(NULL, root_table);
1945 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1947 int err;
1948 err = sysctl_check_table(current->nsproxy, root_table);
1950 #endif
1951 return 0;
1954 core_initcall(sysctl_init);
1956 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1957 struct ctl_table *table)
1959 struct ctl_table *p;
1960 const char *s = branch->procname;
1962 /* branch should have named subdirectory as its first element */
1963 if (!s || !branch->child)
1964 return NULL;
1966 /* ... and nothing else */
1967 if (branch[1].procname || branch[1].ctl_name)
1968 return NULL;
1970 /* table should contain subdirectory with the same name */
1971 for (p = table; p->procname || p->ctl_name; p++) {
1972 if (!p->child)
1973 continue;
1974 if (p->procname && strcmp(p->procname, s) == 0)
1975 return p;
1977 return NULL;
1980 /* see if attaching q to p would be an improvement */
1981 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1983 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1984 struct ctl_table *next;
1985 int is_better = 0;
1986 int not_in_parent = !p->attached_by;
1988 while ((next = is_branch_in(by, to)) != NULL) {
1989 if (by == q->attached_by)
1990 is_better = 1;
1991 if (to == p->attached_by)
1992 not_in_parent = 1;
1993 by = by->child;
1994 to = next->child;
1997 if (is_better && not_in_parent) {
1998 q->attached_by = by;
1999 q->attached_to = to;
2000 q->parent = p;
2005 * __register_sysctl_paths - register a sysctl hierarchy
2006 * @root: List of sysctl headers to register on
2007 * @namespaces: Data to compute which lists of sysctl entries are visible
2008 * @path: The path to the directory the sysctl table is in.
2009 * @table: the top-level table structure
2011 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2012 * array. A completely 0 filled entry terminates the table.
2014 * The members of the &struct ctl_table structure are used as follows:
2016 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
2017 * must be unique within that level of sysctl
2019 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
2020 * enter a sysctl file
2022 * data - a pointer to data for use by proc_handler
2024 * maxlen - the maximum size in bytes of the data
2026 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
2028 * child - a pointer to the child sysctl table if this entry is a directory, or
2029 * %NULL.
2031 * proc_handler - the text handler routine (described below)
2033 * strategy - the strategy routine (described below)
2035 * de - for internal use by the sysctl routines
2037 * extra1, extra2 - extra pointers usable by the proc handler routines
2039 * Leaf nodes in the sysctl tree will be represented by a single file
2040 * under /proc; non-leaf nodes will be represented by directories.
2042 * sysctl(2) can automatically manage read and write requests through
2043 * the sysctl table. The data and maxlen fields of the ctl_table
2044 * struct enable minimal validation of the values being written to be
2045 * performed, and the mode field allows minimal authentication.
2047 * More sophisticated management can be enabled by the provision of a
2048 * strategy routine with the table entry. This will be called before
2049 * any automatic read or write of the data is performed.
2051 * The strategy routine may return
2053 * < 0 - Error occurred (error is passed to user process)
2055 * 0 - OK - proceed with automatic read or write.
2057 * > 0 - OK - read or write has been done by the strategy routine, so
2058 * return immediately.
2060 * There must be a proc_handler routine for any terminal nodes
2061 * mirrored under /proc/sys (non-terminals are handled by a built-in
2062 * directory handler). Several default handlers are available to
2063 * cover common cases -
2065 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
2066 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
2067 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
2069 * It is the handler's job to read the input buffer from user memory
2070 * and process it. The handler should return 0 on success.
2072 * This routine returns %NULL on a failure to register, and a pointer
2073 * to the table header on success.
2075 struct ctl_table_header *__register_sysctl_paths(
2076 struct ctl_table_root *root,
2077 struct nsproxy *namespaces,
2078 const struct ctl_path *path, struct ctl_table *table)
2080 struct ctl_table_header *header;
2081 struct ctl_table *new, **prevp;
2082 unsigned int n, npath;
2083 struct ctl_table_set *set;
2085 /* Count the path components */
2086 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
2090 * For each path component, allocate a 2-element ctl_table array.
2091 * The first array element will be filled with the sysctl entry
2092 * for this, the second will be the sentinel (ctl_name == 0).
2094 * We allocate everything in one go so that we don't have to
2095 * worry about freeing additional memory in unregister_sysctl_table.
2097 header = kzalloc(sizeof(struct ctl_table_header) +
2098 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
2099 if (!header)
2100 return NULL;
2102 new = (struct ctl_table *) (header + 1);
2104 /* Now connect the dots */
2105 prevp = &header->ctl_table;
2106 for (n = 0; n < npath; ++n, ++path) {
2107 /* Copy the procname */
2108 new->procname = path->procname;
2109 new->ctl_name = path->ctl_name;
2110 new->mode = 0555;
2112 *prevp = new;
2113 prevp = &new->child;
2115 new += 2;
2117 *prevp = table;
2118 header->ctl_table_arg = table;
2120 INIT_LIST_HEAD(&header->ctl_entry);
2121 header->used = 0;
2122 header->unregistering = NULL;
2123 header->root = root;
2124 sysctl_set_parent(NULL, header->ctl_table);
2125 header->count = 1;
2126 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
2127 if (sysctl_check_table(namespaces, header->ctl_table)) {
2128 kfree(header);
2129 return NULL;
2131 #endif
2132 spin_lock(&sysctl_lock);
2133 header->set = lookup_header_set(root, namespaces);
2134 header->attached_by = header->ctl_table;
2135 header->attached_to = root_table;
2136 header->parent = &root_table_header;
2137 for (set = header->set; set; set = set->parent) {
2138 struct ctl_table_header *p;
2139 list_for_each_entry(p, &set->list, ctl_entry) {
2140 if (p->unregistering)
2141 continue;
2142 try_attach(p, header);
2145 header->parent->count++;
2146 list_add_tail(&header->ctl_entry, &header->set->list);
2147 spin_unlock(&sysctl_lock);
2149 return header;
2153 * register_sysctl_table_path - register a sysctl table hierarchy
2154 * @path: The path to the directory the sysctl table is in.
2155 * @table: the top-level table structure
2157 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2158 * array. A completely 0 filled entry terminates the table.
2160 * See __register_sysctl_paths for more details.
2162 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2163 struct ctl_table *table)
2165 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
2166 path, table);
2170 * register_sysctl_table - register a sysctl table hierarchy
2171 * @table: the top-level table structure
2173 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
2174 * array. A completely 0 filled entry terminates the table.
2176 * See register_sysctl_paths for more details.
2178 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
2180 static const struct ctl_path null_path[] = { {} };
2182 return register_sysctl_paths(null_path, table);
2186 * unregister_sysctl_table - unregister a sysctl table hierarchy
2187 * @header: the header returned from register_sysctl_table
2189 * Unregisters the sysctl table and all children. proc entries may not
2190 * actually be removed until they are no longer used by anyone.
2192 void unregister_sysctl_table(struct ctl_table_header * header)
2194 might_sleep();
2196 if (header == NULL)
2197 return;
2199 spin_lock(&sysctl_lock);
2200 start_unregistering(header);
2201 if (!--header->parent->count) {
2202 WARN_ON(1);
2203 kfree(header->parent);
2205 if (!--header->count)
2206 kfree(header);
2207 spin_unlock(&sysctl_lock);
2210 int sysctl_is_seen(struct ctl_table_header *p)
2212 struct ctl_table_set *set = p->set;
2213 int res;
2214 spin_lock(&sysctl_lock);
2215 if (p->unregistering)
2216 res = 0;
2217 else if (!set->is_seen)
2218 res = 1;
2219 else
2220 res = set->is_seen(set);
2221 spin_unlock(&sysctl_lock);
2222 return res;
2225 void setup_sysctl_set(struct ctl_table_set *p,
2226 struct ctl_table_set *parent,
2227 int (*is_seen)(struct ctl_table_set *))
2229 INIT_LIST_HEAD(&p->list);
2230 p->parent = parent ? parent : &sysctl_table_root.default_set;
2231 p->is_seen = is_seen;
2234 #else /* !CONFIG_SYSCTL */
2235 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
2237 return NULL;
2240 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2241 struct ctl_table *table)
2243 return NULL;
2246 void unregister_sysctl_table(struct ctl_table_header * table)
2250 void setup_sysctl_set(struct ctl_table_set *p,
2251 struct ctl_table_set *parent,
2252 int (*is_seen)(struct ctl_table_set *))
2256 void sysctl_head_put(struct ctl_table_header *head)
2260 #endif /* CONFIG_SYSCTL */
2263 * /proc/sys support
2266 #ifdef CONFIG_PROC_SYSCTL
2268 static int _proc_do_string(void* data, int maxlen, int write,
2269 void __user *buffer,
2270 size_t *lenp, loff_t *ppos)
2272 size_t len;
2273 char __user *p;
2274 char c;
2276 if (!data || !maxlen || !*lenp) {
2277 *lenp = 0;
2278 return 0;
2281 if (write) {
2282 len = 0;
2283 p = buffer;
2284 while (len < *lenp) {
2285 if (get_user(c, p++))
2286 return -EFAULT;
2287 if (c == 0 || c == '\n')
2288 break;
2289 len++;
2291 if (len >= maxlen)
2292 len = maxlen-1;
2293 if(copy_from_user(data, buffer, len))
2294 return -EFAULT;
2295 ((char *) data)[len] = 0;
2296 *ppos += *lenp;
2297 } else {
2298 len = strlen(data);
2299 if (len > maxlen)
2300 len = maxlen;
2302 if (*ppos > len) {
2303 *lenp = 0;
2304 return 0;
2307 data += *ppos;
2308 len -= *ppos;
2310 if (len > *lenp)
2311 len = *lenp;
2312 if (len)
2313 if(copy_to_user(buffer, data, len))
2314 return -EFAULT;
2315 if (len < *lenp) {
2316 if(put_user('\n', ((char __user *) buffer) + len))
2317 return -EFAULT;
2318 len++;
2320 *lenp = len;
2321 *ppos += len;
2323 return 0;
2327 * proc_dostring - read a string sysctl
2328 * @table: the sysctl table
2329 * @write: %TRUE if this is a write to the sysctl file
2330 * @buffer: the user buffer
2331 * @lenp: the size of the user buffer
2332 * @ppos: file position
2334 * Reads/writes a string from/to the user buffer. If the kernel
2335 * buffer provided is not large enough to hold the string, the
2336 * string is truncated. The copied string is %NULL-terminated.
2337 * If the string is being read by the user process, it is copied
2338 * and a newline '\n' is added. It is truncated if the buffer is
2339 * not large enough.
2341 * Returns 0 on success.
2343 int proc_dostring(struct ctl_table *table, int write,
2344 void __user *buffer, size_t *lenp, loff_t *ppos)
2346 return _proc_do_string(table->data, table->maxlen, write,
2347 buffer, lenp, ppos);
2351 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2352 int *valp,
2353 int write, void *data)
2355 if (write) {
2356 *valp = *negp ? -*lvalp : *lvalp;
2357 } else {
2358 int val = *valp;
2359 if (val < 0) {
2360 *negp = -1;
2361 *lvalp = (unsigned long)-val;
2362 } else {
2363 *negp = 0;
2364 *lvalp = (unsigned long)val;
2367 return 0;
2370 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2371 int write, void __user *buffer,
2372 size_t *lenp, loff_t *ppos,
2373 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2374 int write, void *data),
2375 void *data)
2377 #define TMPBUFLEN 21
2378 int *i, vleft, first = 1, neg;
2379 unsigned long lval;
2380 size_t left, len;
2382 char buf[TMPBUFLEN], *p;
2383 char __user *s = buffer;
2385 if (!tbl_data || !table->maxlen || !*lenp ||
2386 (*ppos && !write)) {
2387 *lenp = 0;
2388 return 0;
2391 i = (int *) tbl_data;
2392 vleft = table->maxlen / sizeof(*i);
2393 left = *lenp;
2395 if (!conv)
2396 conv = do_proc_dointvec_conv;
2398 for (; left && vleft--; i++, first=0) {
2399 if (write) {
2400 while (left) {
2401 char c;
2402 if (get_user(c, s))
2403 return -EFAULT;
2404 if (!isspace(c))
2405 break;
2406 left--;
2407 s++;
2409 if (!left)
2410 break;
2411 neg = 0;
2412 len = left;
2413 if (len > sizeof(buf) - 1)
2414 len = sizeof(buf) - 1;
2415 if (copy_from_user(buf, s, len))
2416 return -EFAULT;
2417 buf[len] = 0;
2418 p = buf;
2419 if (*p == '-' && left > 1) {
2420 neg = 1;
2421 p++;
2423 if (*p < '0' || *p > '9')
2424 break;
2426 lval = simple_strtoul(p, &p, 0);
2428 len = p-buf;
2429 if ((len < left) && *p && !isspace(*p))
2430 break;
2431 s += len;
2432 left -= len;
2434 if (conv(&neg, &lval, i, 1, data))
2435 break;
2436 } else {
2437 p = buf;
2438 if (!first)
2439 *p++ = '\t';
2441 if (conv(&neg, &lval, i, 0, data))
2442 break;
2444 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2445 len = strlen(buf);
2446 if (len > left)
2447 len = left;
2448 if(copy_to_user(s, buf, len))
2449 return -EFAULT;
2450 left -= len;
2451 s += len;
2455 if (!write && !first && left) {
2456 if(put_user('\n', s))
2457 return -EFAULT;
2458 left--, s++;
2460 if (write) {
2461 while (left) {
2462 char c;
2463 if (get_user(c, s++))
2464 return -EFAULT;
2465 if (!isspace(c))
2466 break;
2467 left--;
2470 if (write && first)
2471 return -EINVAL;
2472 *lenp -= left;
2473 *ppos += *lenp;
2474 return 0;
2475 #undef TMPBUFLEN
2478 static int do_proc_dointvec(struct ctl_table *table, int write,
2479 void __user *buffer, size_t *lenp, loff_t *ppos,
2480 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2481 int write, void *data),
2482 void *data)
2484 return __do_proc_dointvec(table->data, table, write,
2485 buffer, lenp, ppos, conv, data);
2489 * proc_dointvec - read a vector of integers
2490 * @table: the sysctl table
2491 * @write: %TRUE if this is a write to the sysctl file
2492 * @buffer: the user buffer
2493 * @lenp: the size of the user buffer
2494 * @ppos: file position
2496 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2497 * values from/to the user buffer, treated as an ASCII string.
2499 * Returns 0 on success.
2501 int proc_dointvec(struct ctl_table *table, int write,
2502 void __user *buffer, size_t *lenp, loff_t *ppos)
2504 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2505 NULL,NULL);
2509 * Taint values can only be increased
2510 * This means we can safely use a temporary.
2512 static int proc_taint(struct ctl_table *table, int write,
2513 void __user *buffer, size_t *lenp, loff_t *ppos)
2515 struct ctl_table t;
2516 unsigned long tmptaint = get_taint();
2517 int err;
2519 if (write && !capable(CAP_SYS_ADMIN))
2520 return -EPERM;
2522 t = *table;
2523 t.data = &tmptaint;
2524 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2525 if (err < 0)
2526 return err;
2528 if (write) {
2530 * Poor man's atomic or. Not worth adding a primitive
2531 * to everyone's atomic.h for this
2533 int i;
2534 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2535 if ((tmptaint >> i) & 1)
2536 add_taint(i);
2540 return err;
2543 struct do_proc_dointvec_minmax_conv_param {
2544 int *min;
2545 int *max;
2548 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2549 int *valp,
2550 int write, void *data)
2552 struct do_proc_dointvec_minmax_conv_param *param = data;
2553 if (write) {
2554 int val = *negp ? -*lvalp : *lvalp;
2555 if ((param->min && *param->min > val) ||
2556 (param->max && *param->max < val))
2557 return -EINVAL;
2558 *valp = val;
2559 } else {
2560 int val = *valp;
2561 if (val < 0) {
2562 *negp = -1;
2563 *lvalp = (unsigned long)-val;
2564 } else {
2565 *negp = 0;
2566 *lvalp = (unsigned long)val;
2569 return 0;
2573 * proc_dointvec_minmax - read a vector of integers with min/max values
2574 * @table: the sysctl table
2575 * @write: %TRUE if this is a write to the sysctl file
2576 * @buffer: the user buffer
2577 * @lenp: the size of the user buffer
2578 * @ppos: file position
2580 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2581 * values from/to the user buffer, treated as an ASCII string.
2583 * This routine will ensure the values are within the range specified by
2584 * table->extra1 (min) and table->extra2 (max).
2586 * Returns 0 on success.
2588 int proc_dointvec_minmax(struct ctl_table *table, int write,
2589 void __user *buffer, size_t *lenp, loff_t *ppos)
2591 struct do_proc_dointvec_minmax_conv_param param = {
2592 .min = (int *) table->extra1,
2593 .max = (int *) table->extra2,
2595 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2596 do_proc_dointvec_minmax_conv, &param);
2599 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2600 void __user *buffer,
2601 size_t *lenp, loff_t *ppos,
2602 unsigned long convmul,
2603 unsigned long convdiv)
2605 #define TMPBUFLEN 21
2606 unsigned long *i, *min, *max, val;
2607 int vleft, first=1, neg;
2608 size_t len, left;
2609 char buf[TMPBUFLEN], *p;
2610 char __user *s = buffer;
2612 if (!data || !table->maxlen || !*lenp ||
2613 (*ppos && !write)) {
2614 *lenp = 0;
2615 return 0;
2618 i = (unsigned long *) data;
2619 min = (unsigned long *) table->extra1;
2620 max = (unsigned long *) table->extra2;
2621 vleft = table->maxlen / sizeof(unsigned long);
2622 left = *lenp;
2624 for (; left && vleft--; i++, min++, max++, first=0) {
2625 if (write) {
2626 while (left) {
2627 char c;
2628 if (get_user(c, s))
2629 return -EFAULT;
2630 if (!isspace(c))
2631 break;
2632 left--;
2633 s++;
2635 if (!left)
2636 break;
2637 neg = 0;
2638 len = left;
2639 if (len > TMPBUFLEN-1)
2640 len = TMPBUFLEN-1;
2641 if (copy_from_user(buf, s, len))
2642 return -EFAULT;
2643 buf[len] = 0;
2644 p = buf;
2645 if (*p == '-' && left > 1) {
2646 neg = 1;
2647 p++;
2649 if (*p < '0' || *p > '9')
2650 break;
2651 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2652 len = p-buf;
2653 if ((len < left) && *p && !isspace(*p))
2654 break;
2655 if (neg)
2656 val = -val;
2657 s += len;
2658 left -= len;
2660 if(neg)
2661 continue;
2662 if ((min && val < *min) || (max && val > *max))
2663 continue;
2664 *i = val;
2665 } else {
2666 p = buf;
2667 if (!first)
2668 *p++ = '\t';
2669 sprintf(p, "%lu", convdiv * (*i) / convmul);
2670 len = strlen(buf);
2671 if (len > left)
2672 len = left;
2673 if(copy_to_user(s, buf, len))
2674 return -EFAULT;
2675 left -= len;
2676 s += len;
2680 if (!write && !first && left) {
2681 if(put_user('\n', s))
2682 return -EFAULT;
2683 left--, s++;
2685 if (write) {
2686 while (left) {
2687 char c;
2688 if (get_user(c, s++))
2689 return -EFAULT;
2690 if (!isspace(c))
2691 break;
2692 left--;
2695 if (write && first)
2696 return -EINVAL;
2697 *lenp -= left;
2698 *ppos += *lenp;
2699 return 0;
2700 #undef TMPBUFLEN
2703 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2704 void __user *buffer,
2705 size_t *lenp, loff_t *ppos,
2706 unsigned long convmul,
2707 unsigned long convdiv)
2709 return __do_proc_doulongvec_minmax(table->data, table, write,
2710 buffer, lenp, ppos, convmul, convdiv);
2714 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2715 * @table: the sysctl table
2716 * @write: %TRUE if this is a write to the sysctl file
2717 * @buffer: the user buffer
2718 * @lenp: the size of the user buffer
2719 * @ppos: file position
2721 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2722 * values from/to the user buffer, treated as an ASCII string.
2724 * This routine will ensure the values are within the range specified by
2725 * table->extra1 (min) and table->extra2 (max).
2727 * Returns 0 on success.
2729 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2730 void __user *buffer, size_t *lenp, loff_t *ppos)
2732 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2736 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2737 * @table: the sysctl table
2738 * @write: %TRUE if this is a write to the sysctl file
2739 * @buffer: the user buffer
2740 * @lenp: the size of the user buffer
2741 * @ppos: file position
2743 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2744 * values from/to the user buffer, treated as an ASCII string. The values
2745 * are treated as milliseconds, and converted to jiffies when they are stored.
2747 * This routine will ensure the values are within the range specified by
2748 * table->extra1 (min) and table->extra2 (max).
2750 * Returns 0 on success.
2752 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2753 void __user *buffer,
2754 size_t *lenp, loff_t *ppos)
2756 return do_proc_doulongvec_minmax(table, write, buffer,
2757 lenp, ppos, HZ, 1000l);
2761 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2762 int *valp,
2763 int write, void *data)
2765 if (write) {
2766 if (*lvalp > LONG_MAX / HZ)
2767 return 1;
2768 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2769 } else {
2770 int val = *valp;
2771 unsigned long lval;
2772 if (val < 0) {
2773 *negp = -1;
2774 lval = (unsigned long)-val;
2775 } else {
2776 *negp = 0;
2777 lval = (unsigned long)val;
2779 *lvalp = lval / HZ;
2781 return 0;
2784 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2785 int *valp,
2786 int write, void *data)
2788 if (write) {
2789 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2790 return 1;
2791 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2792 } else {
2793 int val = *valp;
2794 unsigned long lval;
2795 if (val < 0) {
2796 *negp = -1;
2797 lval = (unsigned long)-val;
2798 } else {
2799 *negp = 0;
2800 lval = (unsigned long)val;
2802 *lvalp = jiffies_to_clock_t(lval);
2804 return 0;
2807 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2808 int *valp,
2809 int write, void *data)
2811 if (write) {
2812 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2813 } else {
2814 int val = *valp;
2815 unsigned long lval;
2816 if (val < 0) {
2817 *negp = -1;
2818 lval = (unsigned long)-val;
2819 } else {
2820 *negp = 0;
2821 lval = (unsigned long)val;
2823 *lvalp = jiffies_to_msecs(lval);
2825 return 0;
2829 * proc_dointvec_jiffies - read a vector of integers as seconds
2830 * @table: the sysctl table
2831 * @write: %TRUE if this is a write to the sysctl file
2832 * @buffer: the user buffer
2833 * @lenp: the size of the user buffer
2834 * @ppos: file position
2836 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2837 * values from/to the user buffer, treated as an ASCII string.
2838 * The values read are assumed to be in seconds, and are converted into
2839 * jiffies.
2841 * Returns 0 on success.
2843 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2844 void __user *buffer, size_t *lenp, loff_t *ppos)
2846 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2847 do_proc_dointvec_jiffies_conv,NULL);
2851 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2852 * @table: the sysctl table
2853 * @write: %TRUE if this is a write to the sysctl file
2854 * @buffer: the user buffer
2855 * @lenp: the size of the user buffer
2856 * @ppos: pointer to the file position
2858 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2859 * values from/to the user buffer, treated as an ASCII string.
2860 * The values read are assumed to be in 1/USER_HZ seconds, and
2861 * are converted into jiffies.
2863 * Returns 0 on success.
2865 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2866 void __user *buffer, size_t *lenp, loff_t *ppos)
2868 return do_proc_dointvec(table,write,buffer,lenp,ppos,
2869 do_proc_dointvec_userhz_jiffies_conv,NULL);
2873 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2874 * @table: the sysctl table
2875 * @write: %TRUE if this is a write to the sysctl file
2876 * @buffer: the user buffer
2877 * @lenp: the size of the user buffer
2878 * @ppos: file position
2879 * @ppos: the current position in the file
2881 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2882 * values from/to the user buffer, treated as an ASCII string.
2883 * The values read are assumed to be in 1/1000 seconds, and
2884 * are converted into jiffies.
2886 * Returns 0 on success.
2888 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2889 void __user *buffer, size_t *lenp, loff_t *ppos)
2891 return do_proc_dointvec(table, write, buffer, lenp, ppos,
2892 do_proc_dointvec_ms_jiffies_conv, NULL);
2895 static int proc_do_cad_pid(struct ctl_table *table, int write,
2896 void __user *buffer, size_t *lenp, loff_t *ppos)
2898 struct pid *new_pid;
2899 pid_t tmp;
2900 int r;
2902 tmp = pid_vnr(cad_pid);
2904 r = __do_proc_dointvec(&tmp, table, write, buffer,
2905 lenp, ppos, NULL, NULL);
2906 if (r || !write)
2907 return r;
2909 new_pid = find_get_pid(tmp);
2910 if (!new_pid)
2911 return -ESRCH;
2913 put_pid(xchg(&cad_pid, new_pid));
2914 return 0;
2917 #else /* CONFIG_PROC_FS */
2919 int proc_dostring(struct ctl_table *table, int write,
2920 void __user *buffer, size_t *lenp, loff_t *ppos)
2922 return -ENOSYS;
2925 int proc_dointvec(struct ctl_table *table, int write,
2926 void __user *buffer, size_t *lenp, loff_t *ppos)
2928 return -ENOSYS;
2931 int proc_dointvec_minmax(struct ctl_table *table, int write,
2932 void __user *buffer, size_t *lenp, loff_t *ppos)
2934 return -ENOSYS;
2937 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2938 void __user *buffer, size_t *lenp, loff_t *ppos)
2940 return -ENOSYS;
2943 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2944 void __user *buffer, size_t *lenp, loff_t *ppos)
2946 return -ENOSYS;
2949 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2950 void __user *buffer, size_t *lenp, loff_t *ppos)
2952 return -ENOSYS;
2955 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2956 void __user *buffer, size_t *lenp, loff_t *ppos)
2958 return -ENOSYS;
2961 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2962 void __user *buffer,
2963 size_t *lenp, loff_t *ppos)
2965 return -ENOSYS;
2969 #endif /* CONFIG_PROC_FS */
2972 #ifdef CONFIG_SYSCTL_SYSCALL
2974 * General sysctl support routines
2977 /* The generic sysctl data routine (used if no strategy routine supplied) */
2978 int sysctl_data(struct ctl_table *table,
2979 void __user *oldval, size_t __user *oldlenp,
2980 void __user *newval, size_t newlen)
2982 size_t len;
2984 /* Get out of I don't have a variable */
2985 if (!table->data || !table->maxlen)
2986 return -ENOTDIR;
2988 if (oldval && oldlenp) {
2989 if (get_user(len, oldlenp))
2990 return -EFAULT;
2991 if (len) {
2992 if (len > table->maxlen)
2993 len = table->maxlen;
2994 if (copy_to_user(oldval, table->data, len))
2995 return -EFAULT;
2996 if (put_user(len, oldlenp))
2997 return -EFAULT;
3001 if (newval && newlen) {
3002 if (newlen > table->maxlen)
3003 newlen = table->maxlen;
3005 if (copy_from_user(table->data, newval, newlen))
3006 return -EFAULT;
3008 return 1;
3011 /* The generic string strategy routine: */
3012 int sysctl_string(struct ctl_table *table,
3013 void __user *oldval, size_t __user *oldlenp,
3014 void __user *newval, size_t newlen)
3016 if (!table->data || !table->maxlen)
3017 return -ENOTDIR;
3019 if (oldval && oldlenp) {
3020 size_t bufsize;
3021 if (get_user(bufsize, oldlenp))
3022 return -EFAULT;
3023 if (bufsize) {
3024 size_t len = strlen(table->data), copied;
3026 /* This shouldn't trigger for a well-formed sysctl */
3027 if (len > table->maxlen)
3028 len = table->maxlen;
3030 /* Copy up to a max of bufsize-1 bytes of the string */
3031 copied = (len >= bufsize) ? bufsize - 1 : len;
3033 if (copy_to_user(oldval, table->data, copied) ||
3034 put_user(0, (char __user *)(oldval + copied)))
3035 return -EFAULT;
3036 if (put_user(len, oldlenp))
3037 return -EFAULT;
3040 if (newval && newlen) {
3041 size_t len = newlen;
3042 if (len > table->maxlen)
3043 len = table->maxlen;
3044 if(copy_from_user(table->data, newval, len))
3045 return -EFAULT;
3046 if (len == table->maxlen)
3047 len--;
3048 ((char *) table->data)[len] = 0;
3050 return 1;
3054 * This function makes sure that all of the integers in the vector
3055 * are between the minimum and maximum values given in the arrays
3056 * table->extra1 and table->extra2, respectively.
3058 int sysctl_intvec(struct ctl_table *table,
3059 void __user *oldval, size_t __user *oldlenp,
3060 void __user *newval, size_t newlen)
3063 if (newval && newlen) {
3064 int __user *vec = (int __user *) newval;
3065 int *min = (int *) table->extra1;
3066 int *max = (int *) table->extra2;
3067 size_t length;
3068 int i;
3070 if (newlen % sizeof(int) != 0)
3071 return -EINVAL;
3073 if (!table->extra1 && !table->extra2)
3074 return 0;
3076 if (newlen > table->maxlen)
3077 newlen = table->maxlen;
3078 length = newlen / sizeof(int);
3080 for (i = 0; i < length; i++) {
3081 int value;
3082 if (get_user(value, vec + i))
3083 return -EFAULT;
3084 if (min && value < min[i])
3085 return -EINVAL;
3086 if (max && value > max[i])
3087 return -EINVAL;
3090 return 0;
3093 /* Strategy function to convert jiffies to seconds */
3094 int sysctl_jiffies(struct ctl_table *table,
3095 void __user *oldval, size_t __user *oldlenp,
3096 void __user *newval, size_t newlen)
3098 if (oldval && oldlenp) {
3099 size_t olen;
3101 if (get_user(olen, oldlenp))
3102 return -EFAULT;
3103 if (olen) {
3104 int val;
3106 if (olen < sizeof(int))
3107 return -EINVAL;
3109 val = *(int *)(table->data) / HZ;
3110 if (put_user(val, (int __user *)oldval))
3111 return -EFAULT;
3112 if (put_user(sizeof(int), oldlenp))
3113 return -EFAULT;
3116 if (newval && newlen) {
3117 int new;
3118 if (newlen != sizeof(int))
3119 return -EINVAL;
3120 if (get_user(new, (int __user *)newval))
3121 return -EFAULT;
3122 *(int *)(table->data) = new*HZ;
3124 return 1;
3127 /* Strategy function to convert jiffies to seconds */
3128 int sysctl_ms_jiffies(struct ctl_table *table,
3129 void __user *oldval, size_t __user *oldlenp,
3130 void __user *newval, size_t newlen)
3132 if (oldval && oldlenp) {
3133 size_t olen;
3135 if (get_user(olen, oldlenp))
3136 return -EFAULT;
3137 if (olen) {
3138 int val;
3140 if (olen < sizeof(int))
3141 return -EINVAL;
3143 val = jiffies_to_msecs(*(int *)(table->data));
3144 if (put_user(val, (int __user *)oldval))
3145 return -EFAULT;
3146 if (put_user(sizeof(int), oldlenp))
3147 return -EFAULT;
3150 if (newval && newlen) {
3151 int new;
3152 if (newlen != sizeof(int))
3153 return -EINVAL;
3154 if (get_user(new, (int __user *)newval))
3155 return -EFAULT;
3156 *(int *)(table->data) = msecs_to_jiffies(new);
3158 return 1;
3163 #else /* CONFIG_SYSCTL_SYSCALL */
3166 SYSCALL_DEFINE1(sysctl, struct __sysctl_args __user *, args)
3168 struct __sysctl_args tmp;
3169 int error;
3171 if (copy_from_user(&tmp, args, sizeof(tmp)))
3172 return -EFAULT;
3174 error = deprecated_sysctl_warning(&tmp);
3176 /* If no error reading the parameters then just -ENOSYS ... */
3177 if (!error)
3178 error = -ENOSYS;
3180 return error;
3183 int sysctl_data(struct ctl_table *table,
3184 void __user *oldval, size_t __user *oldlenp,
3185 void __user *newval, size_t newlen)
3187 return -ENOSYS;
3190 int sysctl_string(struct ctl_table *table,
3191 void __user *oldval, size_t __user *oldlenp,
3192 void __user *newval, size_t newlen)
3194 return -ENOSYS;
3197 int sysctl_intvec(struct ctl_table *table,
3198 void __user *oldval, size_t __user *oldlenp,
3199 void __user *newval, size_t newlen)
3201 return -ENOSYS;
3204 int sysctl_jiffies(struct ctl_table *table,
3205 void __user *oldval, size_t __user *oldlenp,
3206 void __user *newval, size_t newlen)
3208 return -ENOSYS;
3211 int sysctl_ms_jiffies(struct ctl_table *table,
3212 void __user *oldval, size_t __user *oldlenp,
3213 void __user *newval, size_t newlen)
3215 return -ENOSYS;
3218 #endif /* CONFIG_SYSCTL_SYSCALL */
3220 static int deprecated_sysctl_warning(struct __sysctl_args *args)
3222 static int msg_count;
3223 int name[CTL_MAXNAME];
3224 int i;
3226 /* Check args->nlen. */
3227 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3228 return -ENOTDIR;
3230 /* Read in the sysctl name for better debug message logging */
3231 for (i = 0; i < args->nlen; i++)
3232 if (get_user(name[i], args->name + i))
3233 return -EFAULT;
3235 /* Ignore accesses to kernel.version */
3236 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3237 return 0;
3239 if (msg_count < 5) {
3240 msg_count++;
3241 printk(KERN_INFO
3242 "warning: process `%s' used the deprecated sysctl "
3243 "system call with ", current->comm);
3244 for (i = 0; i < args->nlen; i++)
3245 printk("%d.", name[i]);
3246 printk("\n");
3248 return 0;
3252 * No sense putting this after each symbol definition, twice,
3253 * exception granted :-)
3255 EXPORT_SYMBOL(proc_dointvec);
3256 EXPORT_SYMBOL(proc_dointvec_jiffies);
3257 EXPORT_SYMBOL(proc_dointvec_minmax);
3258 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3259 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3260 EXPORT_SYMBOL(proc_dostring);
3261 EXPORT_SYMBOL(proc_doulongvec_minmax);
3262 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3263 EXPORT_SYMBOL(register_sysctl_table);
3264 EXPORT_SYMBOL(register_sysctl_paths);
3265 EXPORT_SYMBOL(sysctl_intvec);
3266 EXPORT_SYMBOL(sysctl_jiffies);
3267 EXPORT_SYMBOL(sysctl_ms_jiffies);
3268 EXPORT_SYMBOL(sysctl_string);
3269 EXPORT_SYMBOL(sysctl_data);
3270 EXPORT_SYMBOL(unregister_sysctl_table);