sparc: fix trivial style issues in kernel/pmc.c
[linux-2.6/mini2440.git] / kernel / sysctl.c
blob4e2ac0aec9b060f3a1a4459f7d6889316d11fdeb
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/utsname.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>
52 #include <asm/uaccess.h>
53 #include <asm/processor.h>
55 #ifdef CONFIG_X86
56 #include <asm/nmi.h>
57 #include <asm/stacktrace.h>
58 #include <asm/io.h>
59 #endif
61 static int deprecated_sysctl_warning(struct __sysctl_args *args);
63 #if defined(CONFIG_SYSCTL)
65 /* External variables not in a header file. */
66 extern int C_A_D;
67 extern int print_fatal_signals;
68 extern int sysctl_overcommit_memory;
69 extern int sysctl_overcommit_ratio;
70 extern int sysctl_panic_on_oom;
71 extern int sysctl_oom_kill_allocating_task;
72 extern int sysctl_oom_dump_tasks;
73 extern int max_threads;
74 extern int core_uses_pid;
75 extern int suid_dumpable;
76 extern char core_pattern[];
77 extern int pid_max;
78 extern int min_free_kbytes;
79 extern int pid_max_min, pid_max_max;
80 extern int sysctl_drop_caches;
81 extern int percpu_pagelist_fraction;
82 extern int compat_log;
83 extern int latencytop_enabled;
84 extern int sysctl_nr_open_min, sysctl_nr_open_max;
85 #ifdef CONFIG_RCU_TORTURE_TEST
86 extern int rcutorture_runnable;
87 #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */
89 /* Constants used for minimum and maximum */
90 #if defined(CONFIG_HIGHMEM) || defined(CONFIG_DETECT_SOFTLOCKUP)
91 static int one = 1;
92 #endif
94 #ifdef CONFIG_DETECT_SOFTLOCKUP
95 static int sixty = 60;
96 static int neg_one = -1;
97 #endif
99 #if defined(CONFIG_MMU) && defined(CONFIG_FILE_LOCKING)
100 static int two = 2;
101 #endif
103 static int zero;
104 static int one_hundred = 100;
106 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
107 static int maxolduid = 65535;
108 static int minolduid;
109 static int min_percpu_pagelist_fract = 8;
111 static int ngroups_max = NGROUPS_MAX;
113 #ifdef CONFIG_MODULES
114 extern char modprobe_path[];
115 #endif
116 #ifdef CONFIG_CHR_DEV_SG
117 extern int sg_big_buff;
118 #endif
120 #ifdef CONFIG_SPARC
121 #include <asm/system.h>
122 #endif
124 #ifdef CONFIG_SPARC64
125 extern int sysctl_tsb_ratio;
126 #endif
128 #ifdef __hppa__
129 extern int pwrsw_enabled;
130 extern int unaligned_enabled;
131 #endif
133 #ifdef CONFIG_S390
134 #ifdef CONFIG_MATHEMU
135 extern int sysctl_ieee_emulation_warnings;
136 #endif
137 extern int sysctl_userprocess_debug;
138 extern int spin_retry;
139 #endif
141 #ifdef CONFIG_BSD_PROCESS_ACCT
142 extern int acct_parm[];
143 #endif
145 #ifdef CONFIG_IA64
146 extern int no_unaligned_warning;
147 #endif
149 #ifdef CONFIG_RT_MUTEXES
150 extern int max_lock_depth;
151 #endif
153 #ifdef CONFIG_PROC_SYSCTL
154 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
155 void __user *buffer, size_t *lenp, loff_t *ppos);
156 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
157 void __user *buffer, size_t *lenp, loff_t *ppos);
158 #endif
160 static struct ctl_table root_table[];
161 static struct ctl_table_root sysctl_table_root;
162 static struct ctl_table_header root_table_header = {
163 .count = 1,
164 .ctl_table = root_table,
165 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.default_set.list),
166 .root = &sysctl_table_root,
167 .set = &sysctl_table_root.default_set,
169 static struct ctl_table_root sysctl_table_root = {
170 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
171 .default_set.list = LIST_HEAD_INIT(root_table_header.ctl_entry),
174 static struct ctl_table kern_table[];
175 static struct ctl_table vm_table[];
176 static struct ctl_table fs_table[];
177 static struct ctl_table debug_table[];
178 static struct ctl_table dev_table[];
179 extern struct ctl_table random_table[];
180 #ifdef CONFIG_INOTIFY_USER
181 extern struct ctl_table inotify_table[];
182 #endif
183 #ifdef CONFIG_EPOLL
184 extern struct ctl_table epoll_table[];
185 #endif
187 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
188 int sysctl_legacy_va_layout;
189 #endif
191 extern int prove_locking;
192 extern int lock_stat;
194 /* The default sysctl tables: */
196 static struct ctl_table root_table[] = {
198 .ctl_name = CTL_KERN,
199 .procname = "kernel",
200 .mode = 0555,
201 .child = kern_table,
204 .ctl_name = CTL_VM,
205 .procname = "vm",
206 .mode = 0555,
207 .child = vm_table,
210 .ctl_name = CTL_FS,
211 .procname = "fs",
212 .mode = 0555,
213 .child = fs_table,
216 .ctl_name = CTL_DEBUG,
217 .procname = "debug",
218 .mode = 0555,
219 .child = debug_table,
222 .ctl_name = CTL_DEV,
223 .procname = "dev",
224 .mode = 0555,
225 .child = dev_table,
228 * NOTE: do not add new entries to this table unless you have read
229 * Documentation/sysctl/ctl_unnumbered.txt
231 { .ctl_name = 0 }
234 #ifdef CONFIG_SCHED_DEBUG
235 static int min_sched_granularity_ns = 100000; /* 100 usecs */
236 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
237 static int min_wakeup_granularity_ns; /* 0 usecs */
238 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
239 #endif
241 static struct ctl_table kern_table[] = {
242 #ifdef CONFIG_SCHED_DEBUG
244 .ctl_name = CTL_UNNUMBERED,
245 .procname = "sched_min_granularity_ns",
246 .data = &sysctl_sched_min_granularity,
247 .maxlen = sizeof(unsigned int),
248 .mode = 0644,
249 .proc_handler = &sched_nr_latency_handler,
250 .strategy = &sysctl_intvec,
251 .extra1 = &min_sched_granularity_ns,
252 .extra2 = &max_sched_granularity_ns,
255 .ctl_name = CTL_UNNUMBERED,
256 .procname = "sched_latency_ns",
257 .data = &sysctl_sched_latency,
258 .maxlen = sizeof(unsigned int),
259 .mode = 0644,
260 .proc_handler = &sched_nr_latency_handler,
261 .strategy = &sysctl_intvec,
262 .extra1 = &min_sched_granularity_ns,
263 .extra2 = &max_sched_granularity_ns,
266 .ctl_name = CTL_UNNUMBERED,
267 .procname = "sched_wakeup_granularity_ns",
268 .data = &sysctl_sched_wakeup_granularity,
269 .maxlen = sizeof(unsigned int),
270 .mode = 0644,
271 .proc_handler = &proc_dointvec_minmax,
272 .strategy = &sysctl_intvec,
273 .extra1 = &min_wakeup_granularity_ns,
274 .extra2 = &max_wakeup_granularity_ns,
277 .ctl_name = CTL_UNNUMBERED,
278 .procname = "sched_shares_ratelimit",
279 .data = &sysctl_sched_shares_ratelimit,
280 .maxlen = sizeof(unsigned int),
281 .mode = 0644,
282 .proc_handler = &proc_dointvec,
285 .ctl_name = CTL_UNNUMBERED,
286 .procname = "sched_shares_thresh",
287 .data = &sysctl_sched_shares_thresh,
288 .maxlen = sizeof(unsigned int),
289 .mode = 0644,
290 .proc_handler = &proc_dointvec_minmax,
291 .strategy = &sysctl_intvec,
292 .extra1 = &zero,
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_child_runs_first",
297 .data = &sysctl_sched_child_runs_first,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
303 .ctl_name = CTL_UNNUMBERED,
304 .procname = "sched_features",
305 .data = &sysctl_sched_features,
306 .maxlen = sizeof(unsigned int),
307 .mode = 0644,
308 .proc_handler = &proc_dointvec,
311 .ctl_name = CTL_UNNUMBERED,
312 .procname = "sched_migration_cost",
313 .data = &sysctl_sched_migration_cost,
314 .maxlen = sizeof(unsigned int),
315 .mode = 0644,
316 .proc_handler = &proc_dointvec,
319 .ctl_name = CTL_UNNUMBERED,
320 .procname = "sched_nr_migrate",
321 .data = &sysctl_sched_nr_migrate,
322 .maxlen = sizeof(unsigned int),
323 .mode = 0644,
324 .proc_handler = &proc_dointvec,
326 #endif
328 .ctl_name = CTL_UNNUMBERED,
329 .procname = "sched_rt_period_us",
330 .data = &sysctl_sched_rt_period,
331 .maxlen = sizeof(unsigned int),
332 .mode = 0644,
333 .proc_handler = &sched_rt_handler,
336 .ctl_name = CTL_UNNUMBERED,
337 .procname = "sched_rt_runtime_us",
338 .data = &sysctl_sched_rt_runtime,
339 .maxlen = sizeof(int),
340 .mode = 0644,
341 .proc_handler = &sched_rt_handler,
344 .ctl_name = CTL_UNNUMBERED,
345 .procname = "sched_compat_yield",
346 .data = &sysctl_sched_compat_yield,
347 .maxlen = sizeof(unsigned int),
348 .mode = 0644,
349 .proc_handler = &proc_dointvec,
351 #ifdef CONFIG_PROVE_LOCKING
353 .ctl_name = CTL_UNNUMBERED,
354 .procname = "prove_locking",
355 .data = &prove_locking,
356 .maxlen = sizeof(int),
357 .mode = 0644,
358 .proc_handler = &proc_dointvec,
360 #endif
361 #ifdef CONFIG_LOCK_STAT
363 .ctl_name = CTL_UNNUMBERED,
364 .procname = "lock_stat",
365 .data = &lock_stat,
366 .maxlen = sizeof(int),
367 .mode = 0644,
368 .proc_handler = &proc_dointvec,
370 #endif
372 .ctl_name = KERN_PANIC,
373 .procname = "panic",
374 .data = &panic_timeout,
375 .maxlen = sizeof(int),
376 .mode = 0644,
377 .proc_handler = &proc_dointvec,
380 .ctl_name = KERN_CORE_USES_PID,
381 .procname = "core_uses_pid",
382 .data = &core_uses_pid,
383 .maxlen = sizeof(int),
384 .mode = 0644,
385 .proc_handler = &proc_dointvec,
388 .ctl_name = KERN_CORE_PATTERN,
389 .procname = "core_pattern",
390 .data = core_pattern,
391 .maxlen = CORENAME_MAX_SIZE,
392 .mode = 0644,
393 .proc_handler = &proc_dostring,
394 .strategy = &sysctl_string,
396 #ifdef CONFIG_PROC_SYSCTL
398 .procname = "tainted",
399 .maxlen = sizeof(long),
400 .mode = 0644,
401 .proc_handler = &proc_taint,
403 #endif
404 #ifdef CONFIG_LATENCYTOP
406 .procname = "latencytop",
407 .data = &latencytop_enabled,
408 .maxlen = sizeof(int),
409 .mode = 0644,
410 .proc_handler = &proc_dointvec,
412 #endif
413 #ifdef CONFIG_BLK_DEV_INITRD
415 .ctl_name = KERN_REALROOTDEV,
416 .procname = "real-root-dev",
417 .data = &real_root_dev,
418 .maxlen = sizeof(int),
419 .mode = 0644,
420 .proc_handler = &proc_dointvec,
422 #endif
424 .ctl_name = CTL_UNNUMBERED,
425 .procname = "print-fatal-signals",
426 .data = &print_fatal_signals,
427 .maxlen = sizeof(int),
428 .mode = 0644,
429 .proc_handler = &proc_dointvec,
431 #ifdef CONFIG_SPARC
433 .ctl_name = KERN_SPARC_REBOOT,
434 .procname = "reboot-cmd",
435 .data = reboot_command,
436 .maxlen = 256,
437 .mode = 0644,
438 .proc_handler = &proc_dostring,
439 .strategy = &sysctl_string,
442 .ctl_name = KERN_SPARC_STOP_A,
443 .procname = "stop-a",
444 .data = &stop_a_enabled,
445 .maxlen = sizeof (int),
446 .mode = 0644,
447 .proc_handler = &proc_dointvec,
450 .ctl_name = KERN_SPARC_SCONS_PWROFF,
451 .procname = "scons-poweroff",
452 .data = &scons_pwroff,
453 .maxlen = sizeof (int),
454 .mode = 0644,
455 .proc_handler = &proc_dointvec,
457 #endif
458 #ifdef CONFIG_SPARC64
460 .ctl_name = CTL_UNNUMBERED,
461 .procname = "tsb-ratio",
462 .data = &sysctl_tsb_ratio,
463 .maxlen = sizeof (int),
464 .mode = 0644,
465 .proc_handler = &proc_dointvec,
467 #endif
468 #ifdef __hppa__
470 .ctl_name = KERN_HPPA_PWRSW,
471 .procname = "soft-power",
472 .data = &pwrsw_enabled,
473 .maxlen = sizeof (int),
474 .mode = 0644,
475 .proc_handler = &proc_dointvec,
478 .ctl_name = KERN_HPPA_UNALIGNED,
479 .procname = "unaligned-trap",
480 .data = &unaligned_enabled,
481 .maxlen = sizeof (int),
482 .mode = 0644,
483 .proc_handler = &proc_dointvec,
485 #endif
487 .ctl_name = KERN_CTLALTDEL,
488 .procname = "ctrl-alt-del",
489 .data = &C_A_D,
490 .maxlen = sizeof(int),
491 .mode = 0644,
492 .proc_handler = &proc_dointvec,
494 #ifdef CONFIG_FUNCTION_TRACER
496 .ctl_name = CTL_UNNUMBERED,
497 .procname = "ftrace_enabled",
498 .data = &ftrace_enabled,
499 .maxlen = sizeof(int),
500 .mode = 0644,
501 .proc_handler = &ftrace_enable_sysctl,
503 #endif
504 #ifdef CONFIG_MODULES
506 .ctl_name = KERN_MODPROBE,
507 .procname = "modprobe",
508 .data = &modprobe_path,
509 .maxlen = KMOD_PATH_LEN,
510 .mode = 0644,
511 .proc_handler = &proc_dostring,
512 .strategy = &sysctl_string,
514 #endif
515 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
517 .ctl_name = KERN_HOTPLUG,
518 .procname = "hotplug",
519 .data = &uevent_helper,
520 .maxlen = UEVENT_HELPER_PATH_LEN,
521 .mode = 0644,
522 .proc_handler = &proc_dostring,
523 .strategy = &sysctl_string,
525 #endif
526 #ifdef CONFIG_CHR_DEV_SG
528 .ctl_name = KERN_SG_BIG_BUFF,
529 .procname = "sg-big-buff",
530 .data = &sg_big_buff,
531 .maxlen = sizeof (int),
532 .mode = 0444,
533 .proc_handler = &proc_dointvec,
535 #endif
536 #ifdef CONFIG_BSD_PROCESS_ACCT
538 .ctl_name = KERN_ACCT,
539 .procname = "acct",
540 .data = &acct_parm,
541 .maxlen = 3*sizeof(int),
542 .mode = 0644,
543 .proc_handler = &proc_dointvec,
545 #endif
546 #ifdef CONFIG_MAGIC_SYSRQ
548 .ctl_name = KERN_SYSRQ,
549 .procname = "sysrq",
550 .data = &__sysrq_enabled,
551 .maxlen = sizeof (int),
552 .mode = 0644,
553 .proc_handler = &proc_dointvec,
555 #endif
556 #ifdef CONFIG_PROC_SYSCTL
558 .procname = "cad_pid",
559 .data = NULL,
560 .maxlen = sizeof (int),
561 .mode = 0600,
562 .proc_handler = &proc_do_cad_pid,
564 #endif
566 .ctl_name = KERN_MAX_THREADS,
567 .procname = "threads-max",
568 .data = &max_threads,
569 .maxlen = sizeof(int),
570 .mode = 0644,
571 .proc_handler = &proc_dointvec,
574 .ctl_name = KERN_RANDOM,
575 .procname = "random",
576 .mode = 0555,
577 .child = random_table,
580 .ctl_name = KERN_OVERFLOWUID,
581 .procname = "overflowuid",
582 .data = &overflowuid,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec_minmax,
586 .strategy = &sysctl_intvec,
587 .extra1 = &minolduid,
588 .extra2 = &maxolduid,
591 .ctl_name = KERN_OVERFLOWGID,
592 .procname = "overflowgid",
593 .data = &overflowgid,
594 .maxlen = sizeof(int),
595 .mode = 0644,
596 .proc_handler = &proc_dointvec_minmax,
597 .strategy = &sysctl_intvec,
598 .extra1 = &minolduid,
599 .extra2 = &maxolduid,
601 #ifdef CONFIG_S390
602 #ifdef CONFIG_MATHEMU
604 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
605 .procname = "ieee_emulation_warnings",
606 .data = &sysctl_ieee_emulation_warnings,
607 .maxlen = sizeof(int),
608 .mode = 0644,
609 .proc_handler = &proc_dointvec,
611 #endif
613 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
614 .procname = "userprocess_debug",
615 .data = &sysctl_userprocess_debug,
616 .maxlen = sizeof(int),
617 .mode = 0644,
618 .proc_handler = &proc_dointvec,
620 #endif
622 .ctl_name = KERN_PIDMAX,
623 .procname = "pid_max",
624 .data = &pid_max,
625 .maxlen = sizeof (int),
626 .mode = 0644,
627 .proc_handler = &proc_dointvec_minmax,
628 .strategy = sysctl_intvec,
629 .extra1 = &pid_max_min,
630 .extra2 = &pid_max_max,
633 .ctl_name = KERN_PANIC_ON_OOPS,
634 .procname = "panic_on_oops",
635 .data = &panic_on_oops,
636 .maxlen = sizeof(int),
637 .mode = 0644,
638 .proc_handler = &proc_dointvec,
640 #if defined CONFIG_PRINTK
642 .ctl_name = KERN_PRINTK,
643 .procname = "printk",
644 .data = &console_loglevel,
645 .maxlen = 4*sizeof(int),
646 .mode = 0644,
647 .proc_handler = &proc_dointvec,
650 .ctl_name = KERN_PRINTK_RATELIMIT,
651 .procname = "printk_ratelimit",
652 .data = &printk_ratelimit_state.interval,
653 .maxlen = sizeof(int),
654 .mode = 0644,
655 .proc_handler = &proc_dointvec_jiffies,
656 .strategy = &sysctl_jiffies,
659 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
660 .procname = "printk_ratelimit_burst",
661 .data = &printk_ratelimit_state.burst,
662 .maxlen = sizeof(int),
663 .mode = 0644,
664 .proc_handler = &proc_dointvec,
666 #endif
668 .ctl_name = KERN_NGROUPS_MAX,
669 .procname = "ngroups_max",
670 .data = &ngroups_max,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = &proc_dointvec,
675 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
677 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
678 .procname = "unknown_nmi_panic",
679 .data = &unknown_nmi_panic,
680 .maxlen = sizeof (int),
681 .mode = 0644,
682 .proc_handler = &proc_dointvec,
685 .procname = "nmi_watchdog",
686 .data = &nmi_watchdog_enabled,
687 .maxlen = sizeof (int),
688 .mode = 0644,
689 .proc_handler = &proc_nmi_enabled,
691 #endif
692 #if defined(CONFIG_X86)
694 .ctl_name = KERN_PANIC_ON_NMI,
695 .procname = "panic_on_unrecovered_nmi",
696 .data = &panic_on_unrecovered_nmi,
697 .maxlen = sizeof(int),
698 .mode = 0644,
699 .proc_handler = &proc_dointvec,
702 .ctl_name = KERN_BOOTLOADER_TYPE,
703 .procname = "bootloader_type",
704 .data = &bootloader_type,
705 .maxlen = sizeof (int),
706 .mode = 0444,
707 .proc_handler = &proc_dointvec,
710 .ctl_name = CTL_UNNUMBERED,
711 .procname = "kstack_depth_to_print",
712 .data = &kstack_depth_to_print,
713 .maxlen = sizeof(int),
714 .mode = 0644,
715 .proc_handler = &proc_dointvec,
718 .ctl_name = CTL_UNNUMBERED,
719 .procname = "io_delay_type",
720 .data = &io_delay_type,
721 .maxlen = sizeof(int),
722 .mode = 0644,
723 .proc_handler = &proc_dointvec,
725 #endif
726 #if defined(CONFIG_MMU)
728 .ctl_name = KERN_RANDOMIZE,
729 .procname = "randomize_va_space",
730 .data = &randomize_va_space,
731 .maxlen = sizeof(int),
732 .mode = 0644,
733 .proc_handler = &proc_dointvec,
735 #endif
736 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
738 .ctl_name = KERN_SPIN_RETRY,
739 .procname = "spin_retry",
740 .data = &spin_retry,
741 .maxlen = sizeof (int),
742 .mode = 0644,
743 .proc_handler = &proc_dointvec,
745 #endif
746 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
748 .procname = "acpi_video_flags",
749 .data = &acpi_realmode_flags,
750 .maxlen = sizeof (unsigned long),
751 .mode = 0644,
752 .proc_handler = &proc_doulongvec_minmax,
754 #endif
755 #ifdef CONFIG_IA64
757 .ctl_name = KERN_IA64_UNALIGNED,
758 .procname = "ignore-unaligned-usertrap",
759 .data = &no_unaligned_warning,
760 .maxlen = sizeof (int),
761 .mode = 0644,
762 .proc_handler = &proc_dointvec,
764 #endif
765 #ifdef CONFIG_DETECT_SOFTLOCKUP
767 .ctl_name = CTL_UNNUMBERED,
768 .procname = "softlockup_panic",
769 .data = &softlockup_panic,
770 .maxlen = sizeof(int),
771 .mode = 0644,
772 .proc_handler = &proc_dointvec_minmax,
773 .strategy = &sysctl_intvec,
774 .extra1 = &zero,
775 .extra2 = &one,
778 .ctl_name = CTL_UNNUMBERED,
779 .procname = "softlockup_thresh",
780 .data = &softlockup_thresh,
781 .maxlen = sizeof(int),
782 .mode = 0644,
783 .proc_handler = &proc_dointvec_minmax,
784 .strategy = &sysctl_intvec,
785 .extra1 = &neg_one,
786 .extra2 = &sixty,
789 .ctl_name = CTL_UNNUMBERED,
790 .procname = "hung_task_check_count",
791 .data = &sysctl_hung_task_check_count,
792 .maxlen = sizeof(unsigned long),
793 .mode = 0644,
794 .proc_handler = &proc_doulongvec_minmax,
795 .strategy = &sysctl_intvec,
798 .ctl_name = CTL_UNNUMBERED,
799 .procname = "hung_task_timeout_secs",
800 .data = &sysctl_hung_task_timeout_secs,
801 .maxlen = sizeof(unsigned long),
802 .mode = 0644,
803 .proc_handler = &proc_doulongvec_minmax,
804 .strategy = &sysctl_intvec,
807 .ctl_name = CTL_UNNUMBERED,
808 .procname = "hung_task_warnings",
809 .data = &sysctl_hung_task_warnings,
810 .maxlen = sizeof(unsigned long),
811 .mode = 0644,
812 .proc_handler = &proc_doulongvec_minmax,
813 .strategy = &sysctl_intvec,
815 #endif
816 #ifdef CONFIG_COMPAT
818 .ctl_name = KERN_COMPAT_LOG,
819 .procname = "compat-log",
820 .data = &compat_log,
821 .maxlen = sizeof (int),
822 .mode = 0644,
823 .proc_handler = &proc_dointvec,
825 #endif
826 #ifdef CONFIG_RT_MUTEXES
828 .ctl_name = KERN_MAX_LOCK_DEPTH,
829 .procname = "max_lock_depth",
830 .data = &max_lock_depth,
831 .maxlen = sizeof(int),
832 .mode = 0644,
833 .proc_handler = &proc_dointvec,
835 #endif
837 .ctl_name = CTL_UNNUMBERED,
838 .procname = "poweroff_cmd",
839 .data = &poweroff_cmd,
840 .maxlen = POWEROFF_CMD_PATH_LEN,
841 .mode = 0644,
842 .proc_handler = &proc_dostring,
843 .strategy = &sysctl_string,
845 #ifdef CONFIG_KEYS
847 .ctl_name = CTL_UNNUMBERED,
848 .procname = "keys",
849 .mode = 0555,
850 .child = key_sysctls,
852 #endif
853 #ifdef CONFIG_RCU_TORTURE_TEST
855 .ctl_name = CTL_UNNUMBERED,
856 .procname = "rcutorture_runnable",
857 .data = &rcutorture_runnable,
858 .maxlen = sizeof(int),
859 .mode = 0644,
860 .proc_handler = &proc_dointvec,
862 #endif
863 #ifdef CONFIG_UNEVICTABLE_LRU
865 .ctl_name = CTL_UNNUMBERED,
866 .procname = "scan_unevictable_pages",
867 .data = &scan_unevictable_pages,
868 .maxlen = sizeof(scan_unevictable_pages),
869 .mode = 0644,
870 .proc_handler = &scan_unevictable_handler,
872 #endif
874 * NOTE: do not add new entries to this table unless you have read
875 * Documentation/sysctl/ctl_unnumbered.txt
877 { .ctl_name = 0 }
880 static struct ctl_table vm_table[] = {
882 .ctl_name = VM_OVERCOMMIT_MEMORY,
883 .procname = "overcommit_memory",
884 .data = &sysctl_overcommit_memory,
885 .maxlen = sizeof(sysctl_overcommit_memory),
886 .mode = 0644,
887 .proc_handler = &proc_dointvec,
890 .ctl_name = VM_PANIC_ON_OOM,
891 .procname = "panic_on_oom",
892 .data = &sysctl_panic_on_oom,
893 .maxlen = sizeof(sysctl_panic_on_oom),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "oom_kill_allocating_task",
900 .data = &sysctl_oom_kill_allocating_task,
901 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
902 .mode = 0644,
903 .proc_handler = &proc_dointvec,
906 .ctl_name = CTL_UNNUMBERED,
907 .procname = "oom_dump_tasks",
908 .data = &sysctl_oom_dump_tasks,
909 .maxlen = sizeof(sysctl_oom_dump_tasks),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec,
914 .ctl_name = VM_OVERCOMMIT_RATIO,
915 .procname = "overcommit_ratio",
916 .data = &sysctl_overcommit_ratio,
917 .maxlen = sizeof(sysctl_overcommit_ratio),
918 .mode = 0644,
919 .proc_handler = &proc_dointvec,
922 .ctl_name = VM_PAGE_CLUSTER,
923 .procname = "page-cluster",
924 .data = &page_cluster,
925 .maxlen = sizeof(int),
926 .mode = 0644,
927 .proc_handler = &proc_dointvec,
930 .ctl_name = VM_DIRTY_BACKGROUND,
931 .procname = "dirty_background_ratio",
932 .data = &dirty_background_ratio,
933 .maxlen = sizeof(dirty_background_ratio),
934 .mode = 0644,
935 .proc_handler = &proc_dointvec_minmax,
936 .strategy = &sysctl_intvec,
937 .extra1 = &zero,
938 .extra2 = &one_hundred,
941 .ctl_name = VM_DIRTY_RATIO,
942 .procname = "dirty_ratio",
943 .data = &vm_dirty_ratio,
944 .maxlen = sizeof(vm_dirty_ratio),
945 .mode = 0644,
946 .proc_handler = &dirty_ratio_handler,
947 .strategy = &sysctl_intvec,
948 .extra1 = &zero,
949 .extra2 = &one_hundred,
952 .procname = "dirty_writeback_centisecs",
953 .data = &dirty_writeback_interval,
954 .maxlen = sizeof(dirty_writeback_interval),
955 .mode = 0644,
956 .proc_handler = &dirty_writeback_centisecs_handler,
959 .procname = "dirty_expire_centisecs",
960 .data = &dirty_expire_interval,
961 .maxlen = sizeof(dirty_expire_interval),
962 .mode = 0644,
963 .proc_handler = &proc_dointvec_userhz_jiffies,
966 .ctl_name = VM_NR_PDFLUSH_THREADS,
967 .procname = "nr_pdflush_threads",
968 .data = &nr_pdflush_threads,
969 .maxlen = sizeof nr_pdflush_threads,
970 .mode = 0444 /* read-only*/,
971 .proc_handler = &proc_dointvec,
974 .ctl_name = VM_SWAPPINESS,
975 .procname = "swappiness",
976 .data = &vm_swappiness,
977 .maxlen = sizeof(vm_swappiness),
978 .mode = 0644,
979 .proc_handler = &proc_dointvec_minmax,
980 .strategy = &sysctl_intvec,
981 .extra1 = &zero,
982 .extra2 = &one_hundred,
984 #ifdef CONFIG_HUGETLB_PAGE
986 .procname = "nr_hugepages",
987 .data = NULL,
988 .maxlen = sizeof(unsigned long),
989 .mode = 0644,
990 .proc_handler = &hugetlb_sysctl_handler,
991 .extra1 = (void *)&hugetlb_zero,
992 .extra2 = (void *)&hugetlb_infinity,
995 .ctl_name = VM_HUGETLB_GROUP,
996 .procname = "hugetlb_shm_group",
997 .data = &sysctl_hugetlb_shm_group,
998 .maxlen = sizeof(gid_t),
999 .mode = 0644,
1000 .proc_handler = &proc_dointvec,
1003 .ctl_name = CTL_UNNUMBERED,
1004 .procname = "hugepages_treat_as_movable",
1005 .data = &hugepages_treat_as_movable,
1006 .maxlen = sizeof(int),
1007 .mode = 0644,
1008 .proc_handler = &hugetlb_treat_movable_handler,
1011 .ctl_name = CTL_UNNUMBERED,
1012 .procname = "nr_overcommit_hugepages",
1013 .data = NULL,
1014 .maxlen = sizeof(unsigned long),
1015 .mode = 0644,
1016 .proc_handler = &hugetlb_overcommit_handler,
1017 .extra1 = (void *)&hugetlb_zero,
1018 .extra2 = (void *)&hugetlb_infinity,
1020 #endif
1022 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
1023 .procname = "lowmem_reserve_ratio",
1024 .data = &sysctl_lowmem_reserve_ratio,
1025 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
1026 .mode = 0644,
1027 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
1028 .strategy = &sysctl_intvec,
1031 .ctl_name = VM_DROP_PAGECACHE,
1032 .procname = "drop_caches",
1033 .data = &sysctl_drop_caches,
1034 .maxlen = sizeof(int),
1035 .mode = 0644,
1036 .proc_handler = drop_caches_sysctl_handler,
1037 .strategy = &sysctl_intvec,
1040 .ctl_name = VM_MIN_FREE_KBYTES,
1041 .procname = "min_free_kbytes",
1042 .data = &min_free_kbytes,
1043 .maxlen = sizeof(min_free_kbytes),
1044 .mode = 0644,
1045 .proc_handler = &min_free_kbytes_sysctl_handler,
1046 .strategy = &sysctl_intvec,
1047 .extra1 = &zero,
1050 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
1051 .procname = "percpu_pagelist_fraction",
1052 .data = &percpu_pagelist_fraction,
1053 .maxlen = sizeof(percpu_pagelist_fraction),
1054 .mode = 0644,
1055 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
1056 .strategy = &sysctl_intvec,
1057 .extra1 = &min_percpu_pagelist_fract,
1059 #ifdef CONFIG_MMU
1061 .ctl_name = VM_MAX_MAP_COUNT,
1062 .procname = "max_map_count",
1063 .data = &sysctl_max_map_count,
1064 .maxlen = sizeof(sysctl_max_map_count),
1065 .mode = 0644,
1066 .proc_handler = &proc_dointvec
1068 #endif
1070 .ctl_name = VM_LAPTOP_MODE,
1071 .procname = "laptop_mode",
1072 .data = &laptop_mode,
1073 .maxlen = sizeof(laptop_mode),
1074 .mode = 0644,
1075 .proc_handler = &proc_dointvec_jiffies,
1076 .strategy = &sysctl_jiffies,
1079 .ctl_name = VM_BLOCK_DUMP,
1080 .procname = "block_dump",
1081 .data = &block_dump,
1082 .maxlen = sizeof(block_dump),
1083 .mode = 0644,
1084 .proc_handler = &proc_dointvec,
1085 .strategy = &sysctl_intvec,
1086 .extra1 = &zero,
1089 .ctl_name = VM_VFS_CACHE_PRESSURE,
1090 .procname = "vfs_cache_pressure",
1091 .data = &sysctl_vfs_cache_pressure,
1092 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1093 .mode = 0644,
1094 .proc_handler = &proc_dointvec,
1095 .strategy = &sysctl_intvec,
1096 .extra1 = &zero,
1098 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1100 .ctl_name = VM_LEGACY_VA_LAYOUT,
1101 .procname = "legacy_va_layout",
1102 .data = &sysctl_legacy_va_layout,
1103 .maxlen = sizeof(sysctl_legacy_va_layout),
1104 .mode = 0644,
1105 .proc_handler = &proc_dointvec,
1106 .strategy = &sysctl_intvec,
1107 .extra1 = &zero,
1109 #endif
1110 #ifdef CONFIG_NUMA
1112 .ctl_name = VM_ZONE_RECLAIM_MODE,
1113 .procname = "zone_reclaim_mode",
1114 .data = &zone_reclaim_mode,
1115 .maxlen = sizeof(zone_reclaim_mode),
1116 .mode = 0644,
1117 .proc_handler = &proc_dointvec,
1118 .strategy = &sysctl_intvec,
1119 .extra1 = &zero,
1122 .ctl_name = VM_MIN_UNMAPPED,
1123 .procname = "min_unmapped_ratio",
1124 .data = &sysctl_min_unmapped_ratio,
1125 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1126 .mode = 0644,
1127 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1128 .strategy = &sysctl_intvec,
1129 .extra1 = &zero,
1130 .extra2 = &one_hundred,
1133 .ctl_name = VM_MIN_SLAB,
1134 .procname = "min_slab_ratio",
1135 .data = &sysctl_min_slab_ratio,
1136 .maxlen = sizeof(sysctl_min_slab_ratio),
1137 .mode = 0644,
1138 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1139 .strategy = &sysctl_intvec,
1140 .extra1 = &zero,
1141 .extra2 = &one_hundred,
1143 #endif
1144 #ifdef CONFIG_SMP
1146 .ctl_name = CTL_UNNUMBERED,
1147 .procname = "stat_interval",
1148 .data = &sysctl_stat_interval,
1149 .maxlen = sizeof(sysctl_stat_interval),
1150 .mode = 0644,
1151 .proc_handler = &proc_dointvec_jiffies,
1152 .strategy = &sysctl_jiffies,
1154 #endif
1155 #ifdef CONFIG_SECURITY
1157 .ctl_name = CTL_UNNUMBERED,
1158 .procname = "mmap_min_addr",
1159 .data = &mmap_min_addr,
1160 .maxlen = sizeof(unsigned long),
1161 .mode = 0644,
1162 .proc_handler = &proc_doulongvec_minmax,
1164 #endif
1165 #ifdef CONFIG_NUMA
1167 .ctl_name = CTL_UNNUMBERED,
1168 .procname = "numa_zonelist_order",
1169 .data = &numa_zonelist_order,
1170 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1171 .mode = 0644,
1172 .proc_handler = &numa_zonelist_order_handler,
1173 .strategy = &sysctl_string,
1175 #endif
1176 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1177 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1179 .ctl_name = VM_VDSO_ENABLED,
1180 .procname = "vdso_enabled",
1181 .data = &vdso_enabled,
1182 .maxlen = sizeof(vdso_enabled),
1183 .mode = 0644,
1184 .proc_handler = &proc_dointvec,
1185 .strategy = &sysctl_intvec,
1186 .extra1 = &zero,
1188 #endif
1189 #ifdef CONFIG_HIGHMEM
1191 .ctl_name = CTL_UNNUMBERED,
1192 .procname = "highmem_is_dirtyable",
1193 .data = &vm_highmem_is_dirtyable,
1194 .maxlen = sizeof(vm_highmem_is_dirtyable),
1195 .mode = 0644,
1196 .proc_handler = &proc_dointvec_minmax,
1197 .strategy = &sysctl_intvec,
1198 .extra1 = &zero,
1199 .extra2 = &one,
1201 #endif
1203 * NOTE: do not add new entries to this table unless you have read
1204 * Documentation/sysctl/ctl_unnumbered.txt
1206 { .ctl_name = 0 }
1209 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1210 static struct ctl_table binfmt_misc_table[] = {
1211 { .ctl_name = 0 }
1213 #endif
1215 static struct ctl_table fs_table[] = {
1217 .ctl_name = FS_NRINODE,
1218 .procname = "inode-nr",
1219 .data = &inodes_stat,
1220 .maxlen = 2*sizeof(int),
1221 .mode = 0444,
1222 .proc_handler = &proc_dointvec,
1225 .ctl_name = FS_STATINODE,
1226 .procname = "inode-state",
1227 .data = &inodes_stat,
1228 .maxlen = 7*sizeof(int),
1229 .mode = 0444,
1230 .proc_handler = &proc_dointvec,
1233 .procname = "file-nr",
1234 .data = &files_stat,
1235 .maxlen = 3*sizeof(int),
1236 .mode = 0444,
1237 .proc_handler = &proc_nr_files,
1240 .ctl_name = FS_MAXFILE,
1241 .procname = "file-max",
1242 .data = &files_stat.max_files,
1243 .maxlen = sizeof(int),
1244 .mode = 0644,
1245 .proc_handler = &proc_dointvec,
1248 .ctl_name = CTL_UNNUMBERED,
1249 .procname = "nr_open",
1250 .data = &sysctl_nr_open,
1251 .maxlen = sizeof(int),
1252 .mode = 0644,
1253 .proc_handler = &proc_dointvec_minmax,
1254 .extra1 = &sysctl_nr_open_min,
1255 .extra2 = &sysctl_nr_open_max,
1258 .ctl_name = FS_DENTRY,
1259 .procname = "dentry-state",
1260 .data = &dentry_stat,
1261 .maxlen = 6*sizeof(int),
1262 .mode = 0444,
1263 .proc_handler = &proc_dointvec,
1266 .ctl_name = FS_OVERFLOWUID,
1267 .procname = "overflowuid",
1268 .data = &fs_overflowuid,
1269 .maxlen = sizeof(int),
1270 .mode = 0644,
1271 .proc_handler = &proc_dointvec_minmax,
1272 .strategy = &sysctl_intvec,
1273 .extra1 = &minolduid,
1274 .extra2 = &maxolduid,
1277 .ctl_name = FS_OVERFLOWGID,
1278 .procname = "overflowgid",
1279 .data = &fs_overflowgid,
1280 .maxlen = sizeof(int),
1281 .mode = 0644,
1282 .proc_handler = &proc_dointvec_minmax,
1283 .strategy = &sysctl_intvec,
1284 .extra1 = &minolduid,
1285 .extra2 = &maxolduid,
1287 #ifdef CONFIG_FILE_LOCKING
1289 .ctl_name = FS_LEASES,
1290 .procname = "leases-enable",
1291 .data = &leases_enable,
1292 .maxlen = sizeof(int),
1293 .mode = 0644,
1294 .proc_handler = &proc_dointvec,
1296 #endif
1297 #ifdef CONFIG_DNOTIFY
1299 .ctl_name = FS_DIR_NOTIFY,
1300 .procname = "dir-notify-enable",
1301 .data = &dir_notify_enable,
1302 .maxlen = sizeof(int),
1303 .mode = 0644,
1304 .proc_handler = &proc_dointvec,
1306 #endif
1307 #ifdef CONFIG_MMU
1308 #ifdef CONFIG_FILE_LOCKING
1310 .ctl_name = FS_LEASE_TIME,
1311 .procname = "lease-break-time",
1312 .data = &lease_break_time,
1313 .maxlen = sizeof(int),
1314 .mode = 0644,
1315 .proc_handler = &proc_dointvec_minmax,
1316 .strategy = &sysctl_intvec,
1317 .extra1 = &zero,
1318 .extra2 = &two,
1320 #endif
1321 #ifdef CONFIG_AIO
1323 .procname = "aio-nr",
1324 .data = &aio_nr,
1325 .maxlen = sizeof(aio_nr),
1326 .mode = 0444,
1327 .proc_handler = &proc_doulongvec_minmax,
1330 .procname = "aio-max-nr",
1331 .data = &aio_max_nr,
1332 .maxlen = sizeof(aio_max_nr),
1333 .mode = 0644,
1334 .proc_handler = &proc_doulongvec_minmax,
1336 #endif /* CONFIG_AIO */
1337 #ifdef CONFIG_INOTIFY_USER
1339 .ctl_name = FS_INOTIFY,
1340 .procname = "inotify",
1341 .mode = 0555,
1342 .child = inotify_table,
1344 #endif
1345 #ifdef CONFIG_EPOLL
1347 .procname = "epoll",
1348 .mode = 0555,
1349 .child = epoll_table,
1351 #endif
1352 #endif
1354 .ctl_name = KERN_SETUID_DUMPABLE,
1355 .procname = "suid_dumpable",
1356 .data = &suid_dumpable,
1357 .maxlen = sizeof(int),
1358 .mode = 0644,
1359 .proc_handler = &proc_dointvec,
1361 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1363 .ctl_name = CTL_UNNUMBERED,
1364 .procname = "binfmt_misc",
1365 .mode = 0555,
1366 .child = binfmt_misc_table,
1368 #endif
1370 * NOTE: do not add new entries to this table unless you have read
1371 * Documentation/sysctl/ctl_unnumbered.txt
1373 { .ctl_name = 0 }
1376 static struct ctl_table debug_table[] = {
1377 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1379 .ctl_name = CTL_UNNUMBERED,
1380 .procname = "exception-trace",
1381 .data = &show_unhandled_signals,
1382 .maxlen = sizeof(int),
1383 .mode = 0644,
1384 .proc_handler = proc_dointvec
1386 #endif
1387 { .ctl_name = 0 }
1390 static struct ctl_table dev_table[] = {
1391 { .ctl_name = 0 }
1394 static DEFINE_SPINLOCK(sysctl_lock);
1396 /* called under sysctl_lock */
1397 static int use_table(struct ctl_table_header *p)
1399 if (unlikely(p->unregistering))
1400 return 0;
1401 p->used++;
1402 return 1;
1405 /* called under sysctl_lock */
1406 static void unuse_table(struct ctl_table_header *p)
1408 if (!--p->used)
1409 if (unlikely(p->unregistering))
1410 complete(p->unregistering);
1413 /* called under sysctl_lock, will reacquire if has to wait */
1414 static void start_unregistering(struct ctl_table_header *p)
1417 * if p->used is 0, nobody will ever touch that entry again;
1418 * we'll eliminate all paths to it before dropping sysctl_lock
1420 if (unlikely(p->used)) {
1421 struct completion wait;
1422 init_completion(&wait);
1423 p->unregistering = &wait;
1424 spin_unlock(&sysctl_lock);
1425 wait_for_completion(&wait);
1426 spin_lock(&sysctl_lock);
1427 } else {
1428 /* anything non-NULL; we'll never dereference it */
1429 p->unregistering = ERR_PTR(-EINVAL);
1432 * do not remove from the list until nobody holds it; walking the
1433 * list in do_sysctl() relies on that.
1435 list_del_init(&p->ctl_entry);
1438 void sysctl_head_get(struct ctl_table_header *head)
1440 spin_lock(&sysctl_lock);
1441 head->count++;
1442 spin_unlock(&sysctl_lock);
1445 void sysctl_head_put(struct ctl_table_header *head)
1447 spin_lock(&sysctl_lock);
1448 if (!--head->count)
1449 kfree(head);
1450 spin_unlock(&sysctl_lock);
1453 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1455 if (!head)
1456 BUG();
1457 spin_lock(&sysctl_lock);
1458 if (!use_table(head))
1459 head = ERR_PTR(-ENOENT);
1460 spin_unlock(&sysctl_lock);
1461 return head;
1464 void sysctl_head_finish(struct ctl_table_header *head)
1466 if (!head)
1467 return;
1468 spin_lock(&sysctl_lock);
1469 unuse_table(head);
1470 spin_unlock(&sysctl_lock);
1473 static struct ctl_table_set *
1474 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1476 struct ctl_table_set *set = &root->default_set;
1477 if (root->lookup)
1478 set = root->lookup(root, namespaces);
1479 return set;
1482 static struct list_head *
1483 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1485 struct ctl_table_set *set = lookup_header_set(root, namespaces);
1486 return &set->list;
1489 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1490 struct ctl_table_header *prev)
1492 struct ctl_table_root *root;
1493 struct list_head *header_list;
1494 struct ctl_table_header *head;
1495 struct list_head *tmp;
1497 spin_lock(&sysctl_lock);
1498 if (prev) {
1499 head = prev;
1500 tmp = &prev->ctl_entry;
1501 unuse_table(prev);
1502 goto next;
1504 tmp = &root_table_header.ctl_entry;
1505 for (;;) {
1506 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1508 if (!use_table(head))
1509 goto next;
1510 spin_unlock(&sysctl_lock);
1511 return head;
1512 next:
1513 root = head->root;
1514 tmp = tmp->next;
1515 header_list = lookup_header_list(root, namespaces);
1516 if (tmp != header_list)
1517 continue;
1519 do {
1520 root = list_entry(root->root_list.next,
1521 struct ctl_table_root, root_list);
1522 if (root == &sysctl_table_root)
1523 goto out;
1524 header_list = lookup_header_list(root, namespaces);
1525 } while (list_empty(header_list));
1526 tmp = header_list->next;
1528 out:
1529 spin_unlock(&sysctl_lock);
1530 return NULL;
1533 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1535 return __sysctl_head_next(current->nsproxy, prev);
1538 void register_sysctl_root(struct ctl_table_root *root)
1540 spin_lock(&sysctl_lock);
1541 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1542 spin_unlock(&sysctl_lock);
1545 #ifdef CONFIG_SYSCTL_SYSCALL
1546 /* Perform the actual read/write of a sysctl table entry. */
1547 static int do_sysctl_strategy(struct ctl_table_root *root,
1548 struct ctl_table *table,
1549 void __user *oldval, size_t __user *oldlenp,
1550 void __user *newval, size_t newlen)
1552 int op = 0, rc;
1554 if (oldval)
1555 op |= MAY_READ;
1556 if (newval)
1557 op |= MAY_WRITE;
1558 if (sysctl_perm(root, table, op))
1559 return -EPERM;
1561 if (table->strategy) {
1562 rc = table->strategy(table, oldval, oldlenp, newval, newlen);
1563 if (rc < 0)
1564 return rc;
1565 if (rc > 0)
1566 return 0;
1569 /* If there is no strategy routine, or if the strategy returns
1570 * zero, proceed with automatic r/w */
1571 if (table->data && table->maxlen) {
1572 rc = sysctl_data(table, oldval, oldlenp, newval, newlen);
1573 if (rc < 0)
1574 return rc;
1576 return 0;
1579 static int parse_table(int __user *name, int nlen,
1580 void __user *oldval, size_t __user *oldlenp,
1581 void __user *newval, size_t newlen,
1582 struct ctl_table_root *root,
1583 struct ctl_table *table)
1585 int n;
1586 repeat:
1587 if (!nlen)
1588 return -ENOTDIR;
1589 if (get_user(n, name))
1590 return -EFAULT;
1591 for ( ; table->ctl_name || table->procname; table++) {
1592 if (!table->ctl_name)
1593 continue;
1594 if (n == table->ctl_name) {
1595 int error;
1596 if (table->child) {
1597 if (sysctl_perm(root, table, MAY_EXEC))
1598 return -EPERM;
1599 name++;
1600 nlen--;
1601 table = table->child;
1602 goto repeat;
1604 error = do_sysctl_strategy(root, table,
1605 oldval, oldlenp,
1606 newval, newlen);
1607 return error;
1610 return -ENOTDIR;
1613 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1614 void __user *newval, size_t newlen)
1616 struct ctl_table_header *head;
1617 int error = -ENOTDIR;
1619 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1620 return -ENOTDIR;
1621 if (oldval) {
1622 int old_len;
1623 if (!oldlenp || get_user(old_len, oldlenp))
1624 return -EFAULT;
1627 for (head = sysctl_head_next(NULL); head;
1628 head = sysctl_head_next(head)) {
1629 error = parse_table(name, nlen, oldval, oldlenp,
1630 newval, newlen,
1631 head->root, head->ctl_table);
1632 if (error != -ENOTDIR) {
1633 sysctl_head_finish(head);
1634 break;
1637 return error;
1640 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1642 struct __sysctl_args tmp;
1643 int error;
1645 if (copy_from_user(&tmp, args, sizeof(tmp)))
1646 return -EFAULT;
1648 error = deprecated_sysctl_warning(&tmp);
1649 if (error)
1650 goto out;
1652 lock_kernel();
1653 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1654 tmp.newval, tmp.newlen);
1655 unlock_kernel();
1656 out:
1657 return error;
1659 #endif /* CONFIG_SYSCTL_SYSCALL */
1662 * sysctl_perm does NOT grant the superuser all rights automatically, because
1663 * some sysctl variables are readonly even to root.
1666 static int test_perm(int mode, int op)
1668 if (!current->euid)
1669 mode >>= 6;
1670 else if (in_egroup_p(0))
1671 mode >>= 3;
1672 if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1673 return 0;
1674 return -EACCES;
1677 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1679 int error;
1680 int mode;
1682 error = security_sysctl(table, op & (MAY_READ | MAY_WRITE | MAY_EXEC));
1683 if (error)
1684 return error;
1686 if (root->permissions)
1687 mode = root->permissions(root, current->nsproxy, table);
1688 else
1689 mode = table->mode;
1691 return test_perm(mode, op);
1694 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1696 for (; table->ctl_name || table->procname; table++) {
1697 table->parent = parent;
1698 if (table->child)
1699 sysctl_set_parent(table, table->child);
1703 static __init int sysctl_init(void)
1705 sysctl_set_parent(NULL, root_table);
1706 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1708 int err;
1709 err = sysctl_check_table(current->nsproxy, root_table);
1711 #endif
1712 return 0;
1715 core_initcall(sysctl_init);
1717 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1718 struct ctl_table *table)
1720 struct ctl_table *p;
1721 const char *s = branch->procname;
1723 /* branch should have named subdirectory as its first element */
1724 if (!s || !branch->child)
1725 return NULL;
1727 /* ... and nothing else */
1728 if (branch[1].procname || branch[1].ctl_name)
1729 return NULL;
1731 /* table should contain subdirectory with the same name */
1732 for (p = table; p->procname || p->ctl_name; p++) {
1733 if (!p->child)
1734 continue;
1735 if (p->procname && strcmp(p->procname, s) == 0)
1736 return p;
1738 return NULL;
1741 /* see if attaching q to p would be an improvement */
1742 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1744 struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1745 struct ctl_table *next;
1746 int is_better = 0;
1747 int not_in_parent = !p->attached_by;
1749 while ((next = is_branch_in(by, to)) != NULL) {
1750 if (by == q->attached_by)
1751 is_better = 1;
1752 if (to == p->attached_by)
1753 not_in_parent = 1;
1754 by = by->child;
1755 to = next->child;
1758 if (is_better && not_in_parent) {
1759 q->attached_by = by;
1760 q->attached_to = to;
1761 q->parent = p;
1766 * __register_sysctl_paths - register a sysctl hierarchy
1767 * @root: List of sysctl headers to register on
1768 * @namespaces: Data to compute which lists of sysctl entries are visible
1769 * @path: The path to the directory the sysctl table is in.
1770 * @table: the top-level table structure
1772 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1773 * array. A completely 0 filled entry terminates the table.
1775 * The members of the &struct ctl_table structure are used as follows:
1777 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1778 * must be unique within that level of sysctl
1780 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1781 * enter a sysctl file
1783 * data - a pointer to data for use by proc_handler
1785 * maxlen - the maximum size in bytes of the data
1787 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1789 * child - a pointer to the child sysctl table if this entry is a directory, or
1790 * %NULL.
1792 * proc_handler - the text handler routine (described below)
1794 * strategy - the strategy routine (described below)
1796 * de - for internal use by the sysctl routines
1798 * extra1, extra2 - extra pointers usable by the proc handler routines
1800 * Leaf nodes in the sysctl tree will be represented by a single file
1801 * under /proc; non-leaf nodes will be represented by directories.
1803 * sysctl(2) can automatically manage read and write requests through
1804 * the sysctl table. The data and maxlen fields of the ctl_table
1805 * struct enable minimal validation of the values being written to be
1806 * performed, and the mode field allows minimal authentication.
1808 * More sophisticated management can be enabled by the provision of a
1809 * strategy routine with the table entry. This will be called before
1810 * any automatic read or write of the data is performed.
1812 * The strategy routine may return
1814 * < 0 - Error occurred (error is passed to user process)
1816 * 0 - OK - proceed with automatic read or write.
1818 * > 0 - OK - read or write has been done by the strategy routine, so
1819 * return immediately.
1821 * There must be a proc_handler routine for any terminal nodes
1822 * mirrored under /proc/sys (non-terminals are handled by a built-in
1823 * directory handler). Several default handlers are available to
1824 * cover common cases -
1826 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1827 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1828 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1830 * It is the handler's job to read the input buffer from user memory
1831 * and process it. The handler should return 0 on success.
1833 * This routine returns %NULL on a failure to register, and a pointer
1834 * to the table header on success.
1836 struct ctl_table_header *__register_sysctl_paths(
1837 struct ctl_table_root *root,
1838 struct nsproxy *namespaces,
1839 const struct ctl_path *path, struct ctl_table *table)
1841 struct ctl_table_header *header;
1842 struct ctl_table *new, **prevp;
1843 unsigned int n, npath;
1844 struct ctl_table_set *set;
1846 /* Count the path components */
1847 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1851 * For each path component, allocate a 2-element ctl_table array.
1852 * The first array element will be filled with the sysctl entry
1853 * for this, the second will be the sentinel (ctl_name == 0).
1855 * We allocate everything in one go so that we don't have to
1856 * worry about freeing additional memory in unregister_sysctl_table.
1858 header = kzalloc(sizeof(struct ctl_table_header) +
1859 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1860 if (!header)
1861 return NULL;
1863 new = (struct ctl_table *) (header + 1);
1865 /* Now connect the dots */
1866 prevp = &header->ctl_table;
1867 for (n = 0; n < npath; ++n, ++path) {
1868 /* Copy the procname */
1869 new->procname = path->procname;
1870 new->ctl_name = path->ctl_name;
1871 new->mode = 0555;
1873 *prevp = new;
1874 prevp = &new->child;
1876 new += 2;
1878 *prevp = table;
1879 header->ctl_table_arg = table;
1881 INIT_LIST_HEAD(&header->ctl_entry);
1882 header->used = 0;
1883 header->unregistering = NULL;
1884 header->root = root;
1885 sysctl_set_parent(NULL, header->ctl_table);
1886 header->count = 1;
1887 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1888 if (sysctl_check_table(namespaces, header->ctl_table)) {
1889 kfree(header);
1890 return NULL;
1892 #endif
1893 spin_lock(&sysctl_lock);
1894 header->set = lookup_header_set(root, namespaces);
1895 header->attached_by = header->ctl_table;
1896 header->attached_to = root_table;
1897 header->parent = &root_table_header;
1898 for (set = header->set; set; set = set->parent) {
1899 struct ctl_table_header *p;
1900 list_for_each_entry(p, &set->list, ctl_entry) {
1901 if (p->unregistering)
1902 continue;
1903 try_attach(p, header);
1906 header->parent->count++;
1907 list_add_tail(&header->ctl_entry, &header->set->list);
1908 spin_unlock(&sysctl_lock);
1910 return header;
1914 * register_sysctl_table_path - register a sysctl table hierarchy
1915 * @path: The path to the directory the sysctl table is in.
1916 * @table: the top-level table structure
1918 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1919 * array. A completely 0 filled entry terminates the table.
1921 * See __register_sysctl_paths for more details.
1923 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1924 struct ctl_table *table)
1926 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1927 path, table);
1931 * register_sysctl_table - register a sysctl table hierarchy
1932 * @table: the top-level table structure
1934 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1935 * array. A completely 0 filled entry terminates the table.
1937 * See register_sysctl_paths for more details.
1939 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1941 static const struct ctl_path null_path[] = { {} };
1943 return register_sysctl_paths(null_path, table);
1947 * unregister_sysctl_table - unregister a sysctl table hierarchy
1948 * @header: the header returned from register_sysctl_table
1950 * Unregisters the sysctl table and all children. proc entries may not
1951 * actually be removed until they are no longer used by anyone.
1953 void unregister_sysctl_table(struct ctl_table_header * header)
1955 might_sleep();
1957 if (header == NULL)
1958 return;
1960 spin_lock(&sysctl_lock);
1961 start_unregistering(header);
1962 if (!--header->parent->count) {
1963 WARN_ON(1);
1964 kfree(header->parent);
1966 if (!--header->count)
1967 kfree(header);
1968 spin_unlock(&sysctl_lock);
1971 int sysctl_is_seen(struct ctl_table_header *p)
1973 struct ctl_table_set *set = p->set;
1974 int res;
1975 spin_lock(&sysctl_lock);
1976 if (p->unregistering)
1977 res = 0;
1978 else if (!set->is_seen)
1979 res = 1;
1980 else
1981 res = set->is_seen(set);
1982 spin_unlock(&sysctl_lock);
1983 return res;
1986 void setup_sysctl_set(struct ctl_table_set *p,
1987 struct ctl_table_set *parent,
1988 int (*is_seen)(struct ctl_table_set *))
1990 INIT_LIST_HEAD(&p->list);
1991 p->parent = parent ? parent : &sysctl_table_root.default_set;
1992 p->is_seen = is_seen;
1995 #else /* !CONFIG_SYSCTL */
1996 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1998 return NULL;
2001 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
2002 struct ctl_table *table)
2004 return NULL;
2007 void unregister_sysctl_table(struct ctl_table_header * table)
2011 void setup_sysctl_set(struct ctl_table_set *p,
2012 struct ctl_table_set *parent,
2013 int (*is_seen)(struct ctl_table_set *))
2017 void sysctl_head_put(struct ctl_table_header *head)
2021 #endif /* CONFIG_SYSCTL */
2024 * /proc/sys support
2027 #ifdef CONFIG_PROC_SYSCTL
2029 static int _proc_do_string(void* data, int maxlen, int write,
2030 struct file *filp, void __user *buffer,
2031 size_t *lenp, loff_t *ppos)
2033 size_t len;
2034 char __user *p;
2035 char c;
2037 if (!data || !maxlen || !*lenp) {
2038 *lenp = 0;
2039 return 0;
2042 if (write) {
2043 len = 0;
2044 p = buffer;
2045 while (len < *lenp) {
2046 if (get_user(c, p++))
2047 return -EFAULT;
2048 if (c == 0 || c == '\n')
2049 break;
2050 len++;
2052 if (len >= maxlen)
2053 len = maxlen-1;
2054 if(copy_from_user(data, buffer, len))
2055 return -EFAULT;
2056 ((char *) data)[len] = 0;
2057 *ppos += *lenp;
2058 } else {
2059 len = strlen(data);
2060 if (len > maxlen)
2061 len = maxlen;
2063 if (*ppos > len) {
2064 *lenp = 0;
2065 return 0;
2068 data += *ppos;
2069 len -= *ppos;
2071 if (len > *lenp)
2072 len = *lenp;
2073 if (len)
2074 if(copy_to_user(buffer, data, len))
2075 return -EFAULT;
2076 if (len < *lenp) {
2077 if(put_user('\n', ((char __user *) buffer) + len))
2078 return -EFAULT;
2079 len++;
2081 *lenp = len;
2082 *ppos += len;
2084 return 0;
2088 * proc_dostring - read a string sysctl
2089 * @table: the sysctl table
2090 * @write: %TRUE if this is a write to the sysctl file
2091 * @filp: the file structure
2092 * @buffer: the user buffer
2093 * @lenp: the size of the user buffer
2094 * @ppos: file position
2096 * Reads/writes a string from/to the user buffer. If the kernel
2097 * buffer provided is not large enough to hold the string, the
2098 * string is truncated. The copied string is %NULL-terminated.
2099 * If the string is being read by the user process, it is copied
2100 * and a newline '\n' is added. It is truncated if the buffer is
2101 * not large enough.
2103 * Returns 0 on success.
2105 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2106 void __user *buffer, size_t *lenp, loff_t *ppos)
2108 return _proc_do_string(table->data, table->maxlen, write, filp,
2109 buffer, lenp, ppos);
2113 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
2114 int *valp,
2115 int write, void *data)
2117 if (write) {
2118 *valp = *negp ? -*lvalp : *lvalp;
2119 } else {
2120 int val = *valp;
2121 if (val < 0) {
2122 *negp = -1;
2123 *lvalp = (unsigned long)-val;
2124 } else {
2125 *negp = 0;
2126 *lvalp = (unsigned long)val;
2129 return 0;
2132 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2133 int write, struct file *filp, void __user *buffer,
2134 size_t *lenp, loff_t *ppos,
2135 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2136 int write, void *data),
2137 void *data)
2139 #define TMPBUFLEN 21
2140 int *i, vleft, first=1, neg, val;
2141 unsigned long lval;
2142 size_t left, len;
2144 char buf[TMPBUFLEN], *p;
2145 char __user *s = buffer;
2147 if (!tbl_data || !table->maxlen || !*lenp ||
2148 (*ppos && !write)) {
2149 *lenp = 0;
2150 return 0;
2153 i = (int *) tbl_data;
2154 vleft = table->maxlen / sizeof(*i);
2155 left = *lenp;
2157 if (!conv)
2158 conv = do_proc_dointvec_conv;
2160 for (; left && vleft--; i++, first=0) {
2161 if (write) {
2162 while (left) {
2163 char c;
2164 if (get_user(c, s))
2165 return -EFAULT;
2166 if (!isspace(c))
2167 break;
2168 left--;
2169 s++;
2171 if (!left)
2172 break;
2173 neg = 0;
2174 len = left;
2175 if (len > sizeof(buf) - 1)
2176 len = sizeof(buf) - 1;
2177 if (copy_from_user(buf, s, len))
2178 return -EFAULT;
2179 buf[len] = 0;
2180 p = buf;
2181 if (*p == '-' && left > 1) {
2182 neg = 1;
2183 p++;
2185 if (*p < '0' || *p > '9')
2186 break;
2188 lval = simple_strtoul(p, &p, 0);
2190 len = p-buf;
2191 if ((len < left) && *p && !isspace(*p))
2192 break;
2193 if (neg)
2194 val = -val;
2195 s += len;
2196 left -= len;
2198 if (conv(&neg, &lval, i, 1, data))
2199 break;
2200 } else {
2201 p = buf;
2202 if (!first)
2203 *p++ = '\t';
2205 if (conv(&neg, &lval, i, 0, data))
2206 break;
2208 sprintf(p, "%s%lu", neg ? "-" : "", lval);
2209 len = strlen(buf);
2210 if (len > left)
2211 len = left;
2212 if(copy_to_user(s, buf, len))
2213 return -EFAULT;
2214 left -= len;
2215 s += len;
2219 if (!write && !first && left) {
2220 if(put_user('\n', s))
2221 return -EFAULT;
2222 left--, s++;
2224 if (write) {
2225 while (left) {
2226 char c;
2227 if (get_user(c, s++))
2228 return -EFAULT;
2229 if (!isspace(c))
2230 break;
2231 left--;
2234 if (write && first)
2235 return -EINVAL;
2236 *lenp -= left;
2237 *ppos += *lenp;
2238 return 0;
2239 #undef TMPBUFLEN
2242 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2243 void __user *buffer, size_t *lenp, loff_t *ppos,
2244 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2245 int write, void *data),
2246 void *data)
2248 return __do_proc_dointvec(table->data, table, write, filp,
2249 buffer, lenp, ppos, conv, data);
2253 * proc_dointvec - read a vector of integers
2254 * @table: the sysctl table
2255 * @write: %TRUE if this is a write to the sysctl file
2256 * @filp: the file structure
2257 * @buffer: the user buffer
2258 * @lenp: the size of the user buffer
2259 * @ppos: file position
2261 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2262 * values from/to the user buffer, treated as an ASCII string.
2264 * Returns 0 on success.
2266 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2267 void __user *buffer, size_t *lenp, loff_t *ppos)
2269 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2270 NULL,NULL);
2274 * Taint values can only be increased
2275 * This means we can safely use a temporary.
2277 static int proc_taint(struct ctl_table *table, int write, struct file *filp,
2278 void __user *buffer, size_t *lenp, loff_t *ppos)
2280 struct ctl_table t;
2281 unsigned long tmptaint = get_taint();
2282 int err;
2284 if (write && !capable(CAP_SYS_ADMIN))
2285 return -EPERM;
2287 t = *table;
2288 t.data = &tmptaint;
2289 err = proc_doulongvec_minmax(&t, write, filp, buffer, lenp, ppos);
2290 if (err < 0)
2291 return err;
2293 if (write) {
2295 * Poor man's atomic or. Not worth adding a primitive
2296 * to everyone's atomic.h for this
2298 int i;
2299 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2300 if ((tmptaint >> i) & 1)
2301 add_taint(i);
2305 return err;
2308 struct do_proc_dointvec_minmax_conv_param {
2309 int *min;
2310 int *max;
2313 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2314 int *valp,
2315 int write, void *data)
2317 struct do_proc_dointvec_minmax_conv_param *param = data;
2318 if (write) {
2319 int val = *negp ? -*lvalp : *lvalp;
2320 if ((param->min && *param->min > val) ||
2321 (param->max && *param->max < val))
2322 return -EINVAL;
2323 *valp = val;
2324 } else {
2325 int val = *valp;
2326 if (val < 0) {
2327 *negp = -1;
2328 *lvalp = (unsigned long)-val;
2329 } else {
2330 *negp = 0;
2331 *lvalp = (unsigned long)val;
2334 return 0;
2338 * proc_dointvec_minmax - read a vector of integers with min/max values
2339 * @table: the sysctl table
2340 * @write: %TRUE if this is a write to the sysctl file
2341 * @filp: the file structure
2342 * @buffer: the user buffer
2343 * @lenp: the size of the user buffer
2344 * @ppos: file position
2346 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2347 * values from/to the user buffer, treated as an ASCII string.
2349 * This routine will ensure the values are within the range specified by
2350 * table->extra1 (min) and table->extra2 (max).
2352 * Returns 0 on success.
2354 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2355 void __user *buffer, size_t *lenp, loff_t *ppos)
2357 struct do_proc_dointvec_minmax_conv_param param = {
2358 .min = (int *) table->extra1,
2359 .max = (int *) table->extra2,
2361 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2362 do_proc_dointvec_minmax_conv, &param);
2365 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2366 struct file *filp,
2367 void __user *buffer,
2368 size_t *lenp, loff_t *ppos,
2369 unsigned long convmul,
2370 unsigned long convdiv)
2372 #define TMPBUFLEN 21
2373 unsigned long *i, *min, *max, val;
2374 int vleft, first=1, neg;
2375 size_t len, left;
2376 char buf[TMPBUFLEN], *p;
2377 char __user *s = buffer;
2379 if (!data || !table->maxlen || !*lenp ||
2380 (*ppos && !write)) {
2381 *lenp = 0;
2382 return 0;
2385 i = (unsigned long *) data;
2386 min = (unsigned long *) table->extra1;
2387 max = (unsigned long *) table->extra2;
2388 vleft = table->maxlen / sizeof(unsigned long);
2389 left = *lenp;
2391 for (; left && vleft--; i++, min++, max++, first=0) {
2392 if (write) {
2393 while (left) {
2394 char c;
2395 if (get_user(c, s))
2396 return -EFAULT;
2397 if (!isspace(c))
2398 break;
2399 left--;
2400 s++;
2402 if (!left)
2403 break;
2404 neg = 0;
2405 len = left;
2406 if (len > TMPBUFLEN-1)
2407 len = TMPBUFLEN-1;
2408 if (copy_from_user(buf, s, len))
2409 return -EFAULT;
2410 buf[len] = 0;
2411 p = buf;
2412 if (*p == '-' && left > 1) {
2413 neg = 1;
2414 p++;
2416 if (*p < '0' || *p > '9')
2417 break;
2418 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2419 len = p-buf;
2420 if ((len < left) && *p && !isspace(*p))
2421 break;
2422 if (neg)
2423 val = -val;
2424 s += len;
2425 left -= len;
2427 if(neg)
2428 continue;
2429 if ((min && val < *min) || (max && val > *max))
2430 continue;
2431 *i = val;
2432 } else {
2433 p = buf;
2434 if (!first)
2435 *p++ = '\t';
2436 sprintf(p, "%lu", convdiv * (*i) / convmul);
2437 len = strlen(buf);
2438 if (len > left)
2439 len = left;
2440 if(copy_to_user(s, buf, len))
2441 return -EFAULT;
2442 left -= len;
2443 s += len;
2447 if (!write && !first && left) {
2448 if(put_user('\n', s))
2449 return -EFAULT;
2450 left--, s++;
2452 if (write) {
2453 while (left) {
2454 char c;
2455 if (get_user(c, s++))
2456 return -EFAULT;
2457 if (!isspace(c))
2458 break;
2459 left--;
2462 if (write && first)
2463 return -EINVAL;
2464 *lenp -= left;
2465 *ppos += *lenp;
2466 return 0;
2467 #undef TMPBUFLEN
2470 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2471 struct file *filp,
2472 void __user *buffer,
2473 size_t *lenp, loff_t *ppos,
2474 unsigned long convmul,
2475 unsigned long convdiv)
2477 return __do_proc_doulongvec_minmax(table->data, table, write,
2478 filp, buffer, lenp, ppos, convmul, convdiv);
2482 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2483 * @table: the sysctl table
2484 * @write: %TRUE if this is a write to the sysctl file
2485 * @filp: the file structure
2486 * @buffer: the user buffer
2487 * @lenp: the size of the user buffer
2488 * @ppos: file position
2490 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2491 * values from/to the user buffer, treated as an ASCII string.
2493 * This routine will ensure the values are within the range specified by
2494 * table->extra1 (min) and table->extra2 (max).
2496 * Returns 0 on success.
2498 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2499 void __user *buffer, size_t *lenp, loff_t *ppos)
2501 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2505 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2506 * @table: the sysctl table
2507 * @write: %TRUE if this is a write to the sysctl file
2508 * @filp: the file structure
2509 * @buffer: the user buffer
2510 * @lenp: the size of the user buffer
2511 * @ppos: file position
2513 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2514 * values from/to the user buffer, treated as an ASCII string. The values
2515 * are treated as milliseconds, and converted to jiffies when they are stored.
2517 * This routine will ensure the values are within the range specified by
2518 * table->extra1 (min) and table->extra2 (max).
2520 * Returns 0 on success.
2522 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2523 struct file *filp,
2524 void __user *buffer,
2525 size_t *lenp, loff_t *ppos)
2527 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2528 lenp, ppos, HZ, 1000l);
2532 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2533 int *valp,
2534 int write, void *data)
2536 if (write) {
2537 if (*lvalp > LONG_MAX / HZ)
2538 return 1;
2539 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2540 } else {
2541 int val = *valp;
2542 unsigned long lval;
2543 if (val < 0) {
2544 *negp = -1;
2545 lval = (unsigned long)-val;
2546 } else {
2547 *negp = 0;
2548 lval = (unsigned long)val;
2550 *lvalp = lval / HZ;
2552 return 0;
2555 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2556 int *valp,
2557 int write, void *data)
2559 if (write) {
2560 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2561 return 1;
2562 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2563 } else {
2564 int val = *valp;
2565 unsigned long lval;
2566 if (val < 0) {
2567 *negp = -1;
2568 lval = (unsigned long)-val;
2569 } else {
2570 *negp = 0;
2571 lval = (unsigned long)val;
2573 *lvalp = jiffies_to_clock_t(lval);
2575 return 0;
2578 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2579 int *valp,
2580 int write, void *data)
2582 if (write) {
2583 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2584 } else {
2585 int val = *valp;
2586 unsigned long lval;
2587 if (val < 0) {
2588 *negp = -1;
2589 lval = (unsigned long)-val;
2590 } else {
2591 *negp = 0;
2592 lval = (unsigned long)val;
2594 *lvalp = jiffies_to_msecs(lval);
2596 return 0;
2600 * proc_dointvec_jiffies - read a vector of integers as seconds
2601 * @table: the sysctl table
2602 * @write: %TRUE if this is a write to the sysctl file
2603 * @filp: the file structure
2604 * @buffer: the user buffer
2605 * @lenp: the size of the user buffer
2606 * @ppos: file position
2608 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2609 * values from/to the user buffer, treated as an ASCII string.
2610 * The values read are assumed to be in seconds, and are converted into
2611 * jiffies.
2613 * Returns 0 on success.
2615 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2616 void __user *buffer, size_t *lenp, loff_t *ppos)
2618 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2619 do_proc_dointvec_jiffies_conv,NULL);
2623 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2624 * @table: the sysctl table
2625 * @write: %TRUE if this is a write to the sysctl file
2626 * @filp: the file structure
2627 * @buffer: the user buffer
2628 * @lenp: the size of the user buffer
2629 * @ppos: pointer to the file position
2631 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2632 * values from/to the user buffer, treated as an ASCII string.
2633 * The values read are assumed to be in 1/USER_HZ seconds, and
2634 * are converted into jiffies.
2636 * Returns 0 on success.
2638 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2639 void __user *buffer, size_t *lenp, loff_t *ppos)
2641 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2642 do_proc_dointvec_userhz_jiffies_conv,NULL);
2646 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2647 * @table: the sysctl table
2648 * @write: %TRUE if this is a write to the sysctl file
2649 * @filp: the file structure
2650 * @buffer: the user buffer
2651 * @lenp: the size of the user buffer
2652 * @ppos: file position
2653 * @ppos: the current position in the file
2655 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2656 * values from/to the user buffer, treated as an ASCII string.
2657 * The values read are assumed to be in 1/1000 seconds, and
2658 * are converted into jiffies.
2660 * Returns 0 on success.
2662 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2663 void __user *buffer, size_t *lenp, loff_t *ppos)
2665 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2666 do_proc_dointvec_ms_jiffies_conv, NULL);
2669 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2670 void __user *buffer, size_t *lenp, loff_t *ppos)
2672 struct pid *new_pid;
2673 pid_t tmp;
2674 int r;
2676 tmp = pid_vnr(cad_pid);
2678 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2679 lenp, ppos, NULL, NULL);
2680 if (r || !write)
2681 return r;
2683 new_pid = find_get_pid(tmp);
2684 if (!new_pid)
2685 return -ESRCH;
2687 put_pid(xchg(&cad_pid, new_pid));
2688 return 0;
2691 #else /* CONFIG_PROC_FS */
2693 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2694 void __user *buffer, size_t *lenp, loff_t *ppos)
2696 return -ENOSYS;
2699 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2700 void __user *buffer, size_t *lenp, loff_t *ppos)
2702 return -ENOSYS;
2705 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2706 void __user *buffer, size_t *lenp, loff_t *ppos)
2708 return -ENOSYS;
2711 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2712 void __user *buffer, size_t *lenp, loff_t *ppos)
2714 return -ENOSYS;
2717 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2718 void __user *buffer, size_t *lenp, loff_t *ppos)
2720 return -ENOSYS;
2723 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2724 void __user *buffer, size_t *lenp, loff_t *ppos)
2726 return -ENOSYS;
2729 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2730 void __user *buffer, size_t *lenp, loff_t *ppos)
2732 return -ENOSYS;
2735 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2736 struct file *filp,
2737 void __user *buffer,
2738 size_t *lenp, loff_t *ppos)
2740 return -ENOSYS;
2744 #endif /* CONFIG_PROC_FS */
2747 #ifdef CONFIG_SYSCTL_SYSCALL
2749 * General sysctl support routines
2752 /* The generic sysctl data routine (used if no strategy routine supplied) */
2753 int sysctl_data(struct ctl_table *table,
2754 void __user *oldval, size_t __user *oldlenp,
2755 void __user *newval, size_t newlen)
2757 size_t len;
2759 /* Get out of I don't have a variable */
2760 if (!table->data || !table->maxlen)
2761 return -ENOTDIR;
2763 if (oldval && oldlenp) {
2764 if (get_user(len, oldlenp))
2765 return -EFAULT;
2766 if (len) {
2767 if (len > table->maxlen)
2768 len = table->maxlen;
2769 if (copy_to_user(oldval, table->data, len))
2770 return -EFAULT;
2771 if (put_user(len, oldlenp))
2772 return -EFAULT;
2776 if (newval && newlen) {
2777 if (newlen > table->maxlen)
2778 newlen = table->maxlen;
2780 if (copy_from_user(table->data, newval, newlen))
2781 return -EFAULT;
2783 return 1;
2786 /* The generic string strategy routine: */
2787 int sysctl_string(struct ctl_table *table,
2788 void __user *oldval, size_t __user *oldlenp,
2789 void __user *newval, size_t newlen)
2791 if (!table->data || !table->maxlen)
2792 return -ENOTDIR;
2794 if (oldval && oldlenp) {
2795 size_t bufsize;
2796 if (get_user(bufsize, oldlenp))
2797 return -EFAULT;
2798 if (bufsize) {
2799 size_t len = strlen(table->data), copied;
2801 /* This shouldn't trigger for a well-formed sysctl */
2802 if (len > table->maxlen)
2803 len = table->maxlen;
2805 /* Copy up to a max of bufsize-1 bytes of the string */
2806 copied = (len >= bufsize) ? bufsize - 1 : len;
2808 if (copy_to_user(oldval, table->data, copied) ||
2809 put_user(0, (char __user *)(oldval + copied)))
2810 return -EFAULT;
2811 if (put_user(len, oldlenp))
2812 return -EFAULT;
2815 if (newval && newlen) {
2816 size_t len = newlen;
2817 if (len > table->maxlen)
2818 len = table->maxlen;
2819 if(copy_from_user(table->data, newval, len))
2820 return -EFAULT;
2821 if (len == table->maxlen)
2822 len--;
2823 ((char *) table->data)[len] = 0;
2825 return 1;
2829 * This function makes sure that all of the integers in the vector
2830 * are between the minimum and maximum values given in the arrays
2831 * table->extra1 and table->extra2, respectively.
2833 int sysctl_intvec(struct ctl_table *table,
2834 void __user *oldval, size_t __user *oldlenp,
2835 void __user *newval, size_t newlen)
2838 if (newval && newlen) {
2839 int __user *vec = (int __user *) newval;
2840 int *min = (int *) table->extra1;
2841 int *max = (int *) table->extra2;
2842 size_t length;
2843 int i;
2845 if (newlen % sizeof(int) != 0)
2846 return -EINVAL;
2848 if (!table->extra1 && !table->extra2)
2849 return 0;
2851 if (newlen > table->maxlen)
2852 newlen = table->maxlen;
2853 length = newlen / sizeof(int);
2855 for (i = 0; i < length; i++) {
2856 int value;
2857 if (get_user(value, vec + i))
2858 return -EFAULT;
2859 if (min && value < min[i])
2860 return -EINVAL;
2861 if (max && value > max[i])
2862 return -EINVAL;
2865 return 0;
2868 /* Strategy function to convert jiffies to seconds */
2869 int sysctl_jiffies(struct ctl_table *table,
2870 void __user *oldval, size_t __user *oldlenp,
2871 void __user *newval, size_t newlen)
2873 if (oldval && oldlenp) {
2874 size_t olen;
2876 if (get_user(olen, oldlenp))
2877 return -EFAULT;
2878 if (olen) {
2879 int val;
2881 if (olen < sizeof(int))
2882 return -EINVAL;
2884 val = *(int *)(table->data) / HZ;
2885 if (put_user(val, (int __user *)oldval))
2886 return -EFAULT;
2887 if (put_user(sizeof(int), oldlenp))
2888 return -EFAULT;
2891 if (newval && newlen) {
2892 int new;
2893 if (newlen != sizeof(int))
2894 return -EINVAL;
2895 if (get_user(new, (int __user *)newval))
2896 return -EFAULT;
2897 *(int *)(table->data) = new*HZ;
2899 return 1;
2902 /* Strategy function to convert jiffies to seconds */
2903 int sysctl_ms_jiffies(struct ctl_table *table,
2904 void __user *oldval, size_t __user *oldlenp,
2905 void __user *newval, size_t newlen)
2907 if (oldval && oldlenp) {
2908 size_t olen;
2910 if (get_user(olen, oldlenp))
2911 return -EFAULT;
2912 if (olen) {
2913 int val;
2915 if (olen < sizeof(int))
2916 return -EINVAL;
2918 val = jiffies_to_msecs(*(int *)(table->data));
2919 if (put_user(val, (int __user *)oldval))
2920 return -EFAULT;
2921 if (put_user(sizeof(int), oldlenp))
2922 return -EFAULT;
2925 if (newval && newlen) {
2926 int new;
2927 if (newlen != sizeof(int))
2928 return -EINVAL;
2929 if (get_user(new, (int __user *)newval))
2930 return -EFAULT;
2931 *(int *)(table->data) = msecs_to_jiffies(new);
2933 return 1;
2938 #else /* CONFIG_SYSCTL_SYSCALL */
2941 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2943 struct __sysctl_args tmp;
2944 int error;
2946 if (copy_from_user(&tmp, args, sizeof(tmp)))
2947 return -EFAULT;
2949 error = deprecated_sysctl_warning(&tmp);
2951 /* If no error reading the parameters then just -ENOSYS ... */
2952 if (!error)
2953 error = -ENOSYS;
2955 return error;
2958 int sysctl_data(struct ctl_table *table,
2959 void __user *oldval, size_t __user *oldlenp,
2960 void __user *newval, size_t newlen)
2962 return -ENOSYS;
2965 int sysctl_string(struct ctl_table *table,
2966 void __user *oldval, size_t __user *oldlenp,
2967 void __user *newval, size_t newlen)
2969 return -ENOSYS;
2972 int sysctl_intvec(struct ctl_table *table,
2973 void __user *oldval, size_t __user *oldlenp,
2974 void __user *newval, size_t newlen)
2976 return -ENOSYS;
2979 int sysctl_jiffies(struct ctl_table *table,
2980 void __user *oldval, size_t __user *oldlenp,
2981 void __user *newval, size_t newlen)
2983 return -ENOSYS;
2986 int sysctl_ms_jiffies(struct ctl_table *table,
2987 void __user *oldval, size_t __user *oldlenp,
2988 void __user *newval, size_t newlen)
2990 return -ENOSYS;
2993 #endif /* CONFIG_SYSCTL_SYSCALL */
2995 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2997 static int msg_count;
2998 int name[CTL_MAXNAME];
2999 int i;
3001 /* Check args->nlen. */
3002 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
3003 return -ENOTDIR;
3005 /* Read in the sysctl name for better debug message logging */
3006 for (i = 0; i < args->nlen; i++)
3007 if (get_user(name[i], args->name + i))
3008 return -EFAULT;
3010 /* Ignore accesses to kernel.version */
3011 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
3012 return 0;
3014 if (msg_count < 5) {
3015 msg_count++;
3016 printk(KERN_INFO
3017 "warning: process `%s' used the deprecated sysctl "
3018 "system call with ", current->comm);
3019 for (i = 0; i < args->nlen; i++)
3020 printk("%d.", name[i]);
3021 printk("\n");
3023 return 0;
3027 * No sense putting this after each symbol definition, twice,
3028 * exception granted :-)
3030 EXPORT_SYMBOL(proc_dointvec);
3031 EXPORT_SYMBOL(proc_dointvec_jiffies);
3032 EXPORT_SYMBOL(proc_dointvec_minmax);
3033 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3034 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3035 EXPORT_SYMBOL(proc_dostring);
3036 EXPORT_SYMBOL(proc_doulongvec_minmax);
3037 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3038 EXPORT_SYMBOL(register_sysctl_table);
3039 EXPORT_SYMBOL(register_sysctl_paths);
3040 EXPORT_SYMBOL(sysctl_intvec);
3041 EXPORT_SYMBOL(sysctl_jiffies);
3042 EXPORT_SYMBOL(sysctl_ms_jiffies);
3043 EXPORT_SYMBOL(sysctl_string);
3044 EXPORT_SYMBOL(sysctl_data);
3045 EXPORT_SYMBOL(unregister_sysctl_table);