update checkpatch.pl to version 0.17
[linux-2.6/mini2440.git] / kernel / sysctl.c
blobfd3364827ccf0a838c79fe240016c93cedd508e4
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/times.h>
42 #include <linux/limits.h>
43 #include <linux/dcache.h>
44 #include <linux/syscalls.h>
45 #include <linux/nfs_fs.h>
46 #include <linux/acpi.h>
47 #include <linux/reboot.h>
49 #include <asm/uaccess.h>
50 #include <asm/processor.h>
52 #ifdef CONFIG_X86
53 #include <asm/nmi.h>
54 #include <asm/stacktrace.h>
55 #include <asm/io.h>
56 #endif
58 static int deprecated_sysctl_warning(struct __sysctl_args *args);
60 #if defined(CONFIG_SYSCTL)
62 /* External variables not in a header file. */
63 extern int C_A_D;
64 extern int print_fatal_signals;
65 extern int sysctl_overcommit_memory;
66 extern int sysctl_overcommit_ratio;
67 extern int sysctl_panic_on_oom;
68 extern int sysctl_oom_kill_allocating_task;
69 extern int sysctl_oom_dump_tasks;
70 extern int max_threads;
71 extern int core_uses_pid;
72 extern int suid_dumpable;
73 extern char core_pattern[];
74 extern int pid_max;
75 extern int min_free_kbytes;
76 extern int pid_max_min, pid_max_max;
77 extern int sysctl_drop_caches;
78 extern int percpu_pagelist_fraction;
79 extern int compat_log;
80 extern int maps_protect;
81 extern int sysctl_stat_interval;
82 extern int latencytop_enabled;
84 /* Constants used for minimum and maximum */
85 #if defined(CONFIG_DETECT_SOFTLOCKUP) || defined(CONFIG_HIGHMEM)
86 static int one = 1;
87 #endif
89 #ifdef CONFIG_DETECT_SOFTLOCKUP
90 static int sixty = 60;
91 #endif
93 #ifdef CONFIG_MMU
94 static int two = 2;
95 #endif
97 static int zero;
98 static int one_hundred = 100;
100 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
101 static int maxolduid = 65535;
102 static int minolduid;
103 static int min_percpu_pagelist_fract = 8;
105 static int ngroups_max = NGROUPS_MAX;
107 #ifdef CONFIG_KMOD
108 extern char modprobe_path[];
109 #endif
110 #ifdef CONFIG_CHR_DEV_SG
111 extern int sg_big_buff;
112 #endif
114 #ifdef __sparc__
115 extern char reboot_command [];
116 extern int stop_a_enabled;
117 extern int scons_pwroff;
118 #endif
120 #ifdef __hppa__
121 extern int pwrsw_enabled;
122 extern int unaligned_enabled;
123 #endif
125 #ifdef CONFIG_S390
126 #ifdef CONFIG_MATHEMU
127 extern int sysctl_ieee_emulation_warnings;
128 #endif
129 extern int sysctl_userprocess_debug;
130 extern int spin_retry;
131 #endif
133 extern int sysctl_hz_timer;
135 #ifdef CONFIG_BSD_PROCESS_ACCT
136 extern int acct_parm[];
137 #endif
139 #ifdef CONFIG_IA64
140 extern int no_unaligned_warning;
141 #endif
143 #ifdef CONFIG_RT_MUTEXES
144 extern int max_lock_depth;
145 #endif
147 #ifdef CONFIG_SYSCTL_SYSCALL
148 static int parse_table(int __user *, int, void __user *, size_t __user *,
149 void __user *, size_t, struct ctl_table *);
150 #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_dointvec_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 .ctl_table = root_table,
164 .ctl_entry = LIST_HEAD_INIT(sysctl_table_root.header_list),
165 .root = &sysctl_table_root,
167 static struct ctl_table_root sysctl_table_root = {
168 .root_list = LIST_HEAD_INIT(sysctl_table_root.root_list),
169 .header_list = LIST_HEAD_INIT(root_table_header.ctl_entry),
172 static struct ctl_table kern_table[];
173 static struct ctl_table vm_table[];
174 static struct ctl_table fs_table[];
175 static struct ctl_table debug_table[];
176 static struct ctl_table dev_table[];
177 extern struct ctl_table random_table[];
178 #ifdef CONFIG_INOTIFY_USER
179 extern struct ctl_table inotify_table[];
180 #endif
182 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
183 int sysctl_legacy_va_layout;
184 #endif
186 extern int prove_locking;
187 extern int lock_stat;
189 /* The default sysctl tables: */
191 static struct ctl_table root_table[] = {
193 .ctl_name = CTL_KERN,
194 .procname = "kernel",
195 .mode = 0555,
196 .child = kern_table,
199 .ctl_name = CTL_VM,
200 .procname = "vm",
201 .mode = 0555,
202 .child = vm_table,
205 .ctl_name = CTL_FS,
206 .procname = "fs",
207 .mode = 0555,
208 .child = fs_table,
211 .ctl_name = CTL_DEBUG,
212 .procname = "debug",
213 .mode = 0555,
214 .child = debug_table,
217 .ctl_name = CTL_DEV,
218 .procname = "dev",
219 .mode = 0555,
220 .child = dev_table,
223 * NOTE: do not add new entries to this table unless you have read
224 * Documentation/sysctl/ctl_unnumbered.txt
226 { .ctl_name = 0 }
229 #ifdef CONFIG_SCHED_DEBUG
230 static int min_sched_granularity_ns = 100000; /* 100 usecs */
231 static int max_sched_granularity_ns = NSEC_PER_SEC; /* 1 second */
232 static int min_wakeup_granularity_ns; /* 0 usecs */
233 static int max_wakeup_granularity_ns = NSEC_PER_SEC; /* 1 second */
234 #endif
236 static struct ctl_table kern_table[] = {
237 #ifdef CONFIG_SCHED_DEBUG
239 .ctl_name = CTL_UNNUMBERED,
240 .procname = "sched_min_granularity_ns",
241 .data = &sysctl_sched_min_granularity,
242 .maxlen = sizeof(unsigned int),
243 .mode = 0644,
244 .proc_handler = &sched_nr_latency_handler,
245 .strategy = &sysctl_intvec,
246 .extra1 = &min_sched_granularity_ns,
247 .extra2 = &max_sched_granularity_ns,
250 .ctl_name = CTL_UNNUMBERED,
251 .procname = "sched_latency_ns",
252 .data = &sysctl_sched_latency,
253 .maxlen = sizeof(unsigned int),
254 .mode = 0644,
255 .proc_handler = &sched_nr_latency_handler,
256 .strategy = &sysctl_intvec,
257 .extra1 = &min_sched_granularity_ns,
258 .extra2 = &max_sched_granularity_ns,
261 .ctl_name = CTL_UNNUMBERED,
262 .procname = "sched_wakeup_granularity_ns",
263 .data = &sysctl_sched_wakeup_granularity,
264 .maxlen = sizeof(unsigned int),
265 .mode = 0644,
266 .proc_handler = &proc_dointvec_minmax,
267 .strategy = &sysctl_intvec,
268 .extra1 = &min_wakeup_granularity_ns,
269 .extra2 = &max_wakeup_granularity_ns,
272 .ctl_name = CTL_UNNUMBERED,
273 .procname = "sched_child_runs_first",
274 .data = &sysctl_sched_child_runs_first,
275 .maxlen = sizeof(unsigned int),
276 .mode = 0644,
277 .proc_handler = &proc_dointvec,
280 .ctl_name = CTL_UNNUMBERED,
281 .procname = "sched_features",
282 .data = &sysctl_sched_features,
283 .maxlen = sizeof(unsigned int),
284 .mode = 0644,
285 .proc_handler = &proc_dointvec,
288 .ctl_name = CTL_UNNUMBERED,
289 .procname = "sched_migration_cost",
290 .data = &sysctl_sched_migration_cost,
291 .maxlen = sizeof(unsigned int),
292 .mode = 0644,
293 .proc_handler = &proc_dointvec,
296 .ctl_name = CTL_UNNUMBERED,
297 .procname = "sched_nr_migrate",
298 .data = &sysctl_sched_nr_migrate,
299 .maxlen = sizeof(unsigned int),
300 .mode = 0644,
301 .proc_handler = &proc_dointvec,
303 #endif
305 .ctl_name = CTL_UNNUMBERED,
306 .procname = "sched_rt_period_us",
307 .data = &sysctl_sched_rt_period,
308 .maxlen = sizeof(unsigned int),
309 .mode = 0644,
310 .proc_handler = &sched_rt_handler,
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "sched_rt_runtime_us",
315 .data = &sysctl_sched_rt_runtime,
316 .maxlen = sizeof(int),
317 .mode = 0644,
318 .proc_handler = &sched_rt_handler,
321 .ctl_name = CTL_UNNUMBERED,
322 .procname = "sched_compat_yield",
323 .data = &sysctl_sched_compat_yield,
324 .maxlen = sizeof(unsigned int),
325 .mode = 0644,
326 .proc_handler = &proc_dointvec,
328 #ifdef CONFIG_PROVE_LOCKING
330 .ctl_name = CTL_UNNUMBERED,
331 .procname = "prove_locking",
332 .data = &prove_locking,
333 .maxlen = sizeof(int),
334 .mode = 0644,
335 .proc_handler = &proc_dointvec,
337 #endif
338 #ifdef CONFIG_LOCK_STAT
340 .ctl_name = CTL_UNNUMBERED,
341 .procname = "lock_stat",
342 .data = &lock_stat,
343 .maxlen = sizeof(int),
344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
347 #endif
349 .ctl_name = KERN_PANIC,
350 .procname = "panic",
351 .data = &panic_timeout,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
357 .ctl_name = KERN_CORE_USES_PID,
358 .procname = "core_uses_pid",
359 .data = &core_uses_pid,
360 .maxlen = sizeof(int),
361 .mode = 0644,
362 .proc_handler = &proc_dointvec,
365 .ctl_name = KERN_CORE_PATTERN,
366 .procname = "core_pattern",
367 .data = core_pattern,
368 .maxlen = CORENAME_MAX_SIZE,
369 .mode = 0644,
370 .proc_handler = &proc_dostring,
371 .strategy = &sysctl_string,
373 #ifdef CONFIG_PROC_SYSCTL
375 .procname = "tainted",
376 .data = &tainted,
377 .maxlen = sizeof(int),
378 .mode = 0644,
379 .proc_handler = &proc_dointvec_taint,
381 #endif
382 #ifdef CONFIG_LATENCYTOP
384 .procname = "latencytop",
385 .data = &latencytop_enabled,
386 .maxlen = sizeof(int),
387 .mode = 0644,
388 .proc_handler = &proc_dointvec,
390 #endif
391 #ifdef CONFIG_BLK_DEV_INITRD
393 .ctl_name = KERN_REALROOTDEV,
394 .procname = "real-root-dev",
395 .data = &real_root_dev,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
400 #endif
402 .ctl_name = CTL_UNNUMBERED,
403 .procname = "print-fatal-signals",
404 .data = &print_fatal_signals,
405 .maxlen = sizeof(int),
406 .mode = 0644,
407 .proc_handler = &proc_dointvec,
409 #ifdef __sparc__
411 .ctl_name = KERN_SPARC_REBOOT,
412 .procname = "reboot-cmd",
413 .data = reboot_command,
414 .maxlen = 256,
415 .mode = 0644,
416 .proc_handler = &proc_dostring,
417 .strategy = &sysctl_string,
420 .ctl_name = KERN_SPARC_STOP_A,
421 .procname = "stop-a",
422 .data = &stop_a_enabled,
423 .maxlen = sizeof (int),
424 .mode = 0644,
425 .proc_handler = &proc_dointvec,
428 .ctl_name = KERN_SPARC_SCONS_PWROFF,
429 .procname = "scons-poweroff",
430 .data = &scons_pwroff,
431 .maxlen = sizeof (int),
432 .mode = 0644,
433 .proc_handler = &proc_dointvec,
435 #endif
436 #ifdef __hppa__
438 .ctl_name = KERN_HPPA_PWRSW,
439 .procname = "soft-power",
440 .data = &pwrsw_enabled,
441 .maxlen = sizeof (int),
442 .mode = 0644,
443 .proc_handler = &proc_dointvec,
446 .ctl_name = KERN_HPPA_UNALIGNED,
447 .procname = "unaligned-trap",
448 .data = &unaligned_enabled,
449 .maxlen = sizeof (int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
453 #endif
455 .ctl_name = KERN_CTLALTDEL,
456 .procname = "ctrl-alt-del",
457 .data = &C_A_D,
458 .maxlen = sizeof(int),
459 .mode = 0644,
460 .proc_handler = &proc_dointvec,
462 #ifdef CONFIG_KMOD
464 .ctl_name = KERN_MODPROBE,
465 .procname = "modprobe",
466 .data = &modprobe_path,
467 .maxlen = KMOD_PATH_LEN,
468 .mode = 0644,
469 .proc_handler = &proc_dostring,
470 .strategy = &sysctl_string,
472 #endif
473 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
475 .ctl_name = KERN_HOTPLUG,
476 .procname = "hotplug",
477 .data = &uevent_helper,
478 .maxlen = UEVENT_HELPER_PATH_LEN,
479 .mode = 0644,
480 .proc_handler = &proc_dostring,
481 .strategy = &sysctl_string,
483 #endif
484 #ifdef CONFIG_CHR_DEV_SG
486 .ctl_name = KERN_SG_BIG_BUFF,
487 .procname = "sg-big-buff",
488 .data = &sg_big_buff,
489 .maxlen = sizeof (int),
490 .mode = 0444,
491 .proc_handler = &proc_dointvec,
493 #endif
494 #ifdef CONFIG_BSD_PROCESS_ACCT
496 .ctl_name = KERN_ACCT,
497 .procname = "acct",
498 .data = &acct_parm,
499 .maxlen = 3*sizeof(int),
500 .mode = 0644,
501 .proc_handler = &proc_dointvec,
503 #endif
504 #ifdef CONFIG_MAGIC_SYSRQ
506 .ctl_name = KERN_SYSRQ,
507 .procname = "sysrq",
508 .data = &__sysrq_enabled,
509 .maxlen = sizeof (int),
510 .mode = 0644,
511 .proc_handler = &proc_dointvec,
513 #endif
514 #ifdef CONFIG_PROC_SYSCTL
516 .procname = "cad_pid",
517 .data = NULL,
518 .maxlen = sizeof (int),
519 .mode = 0600,
520 .proc_handler = &proc_do_cad_pid,
522 #endif
524 .ctl_name = KERN_MAX_THREADS,
525 .procname = "threads-max",
526 .data = &max_threads,
527 .maxlen = sizeof(int),
528 .mode = 0644,
529 .proc_handler = &proc_dointvec,
532 .ctl_name = KERN_RANDOM,
533 .procname = "random",
534 .mode = 0555,
535 .child = random_table,
538 .ctl_name = KERN_OVERFLOWUID,
539 .procname = "overflowuid",
540 .data = &overflowuid,
541 .maxlen = sizeof(int),
542 .mode = 0644,
543 .proc_handler = &proc_dointvec_minmax,
544 .strategy = &sysctl_intvec,
545 .extra1 = &minolduid,
546 .extra2 = &maxolduid,
549 .ctl_name = KERN_OVERFLOWGID,
550 .procname = "overflowgid",
551 .data = &overflowgid,
552 .maxlen = sizeof(int),
553 .mode = 0644,
554 .proc_handler = &proc_dointvec_minmax,
555 .strategy = &sysctl_intvec,
556 .extra1 = &minolduid,
557 .extra2 = &maxolduid,
559 #ifdef CONFIG_S390
560 #ifdef CONFIG_MATHEMU
562 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
563 .procname = "ieee_emulation_warnings",
564 .data = &sysctl_ieee_emulation_warnings,
565 .maxlen = sizeof(int),
566 .mode = 0644,
567 .proc_handler = &proc_dointvec,
569 #endif
570 #ifdef CONFIG_NO_IDLE_HZ
572 .ctl_name = KERN_HZ_TIMER,
573 .procname = "hz_timer",
574 .data = &sysctl_hz_timer,
575 .maxlen = sizeof(int),
576 .mode = 0644,
577 .proc_handler = &proc_dointvec,
579 #endif
581 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
582 .procname = "userprocess_debug",
583 .data = &sysctl_userprocess_debug,
584 .maxlen = sizeof(int),
585 .mode = 0644,
586 .proc_handler = &proc_dointvec,
588 #endif
590 .ctl_name = KERN_PIDMAX,
591 .procname = "pid_max",
592 .data = &pid_max,
593 .maxlen = sizeof (int),
594 .mode = 0644,
595 .proc_handler = &proc_dointvec_minmax,
596 .strategy = sysctl_intvec,
597 .extra1 = &pid_max_min,
598 .extra2 = &pid_max_max,
601 .ctl_name = KERN_PANIC_ON_OOPS,
602 .procname = "panic_on_oops",
603 .data = &panic_on_oops,
604 .maxlen = sizeof(int),
605 .mode = 0644,
606 .proc_handler = &proc_dointvec,
608 #if defined CONFIG_PRINTK
610 .ctl_name = KERN_PRINTK,
611 .procname = "printk",
612 .data = &console_loglevel,
613 .maxlen = 4*sizeof(int),
614 .mode = 0644,
615 .proc_handler = &proc_dointvec,
618 .ctl_name = KERN_PRINTK_RATELIMIT,
619 .procname = "printk_ratelimit",
620 .data = &printk_ratelimit_jiffies,
621 .maxlen = sizeof(int),
622 .mode = 0644,
623 .proc_handler = &proc_dointvec_jiffies,
624 .strategy = &sysctl_jiffies,
627 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
628 .procname = "printk_ratelimit_burst",
629 .data = &printk_ratelimit_burst,
630 .maxlen = sizeof(int),
631 .mode = 0644,
632 .proc_handler = &proc_dointvec,
634 #endif
636 .ctl_name = KERN_NGROUPS_MAX,
637 .procname = "ngroups_max",
638 .data = &ngroups_max,
639 .maxlen = sizeof (int),
640 .mode = 0444,
641 .proc_handler = &proc_dointvec,
643 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
645 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
646 .procname = "unknown_nmi_panic",
647 .data = &unknown_nmi_panic,
648 .maxlen = sizeof (int),
649 .mode = 0644,
650 .proc_handler = &proc_dointvec,
653 .procname = "nmi_watchdog",
654 .data = &nmi_watchdog_enabled,
655 .maxlen = sizeof (int),
656 .mode = 0644,
657 .proc_handler = &proc_nmi_enabled,
659 #endif
660 #if defined(CONFIG_X86)
662 .ctl_name = KERN_PANIC_ON_NMI,
663 .procname = "panic_on_unrecovered_nmi",
664 .data = &panic_on_unrecovered_nmi,
665 .maxlen = sizeof(int),
666 .mode = 0644,
667 .proc_handler = &proc_dointvec,
670 .ctl_name = KERN_BOOTLOADER_TYPE,
671 .procname = "bootloader_type",
672 .data = &bootloader_type,
673 .maxlen = sizeof (int),
674 .mode = 0444,
675 .proc_handler = &proc_dointvec,
678 .ctl_name = CTL_UNNUMBERED,
679 .procname = "kstack_depth_to_print",
680 .data = &kstack_depth_to_print,
681 .maxlen = sizeof(int),
682 .mode = 0644,
683 .proc_handler = &proc_dointvec,
686 .ctl_name = CTL_UNNUMBERED,
687 .procname = "io_delay_type",
688 .data = &io_delay_type,
689 .maxlen = sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
693 #endif
694 #if defined(CONFIG_MMU)
696 .ctl_name = KERN_RANDOMIZE,
697 .procname = "randomize_va_space",
698 .data = &randomize_va_space,
699 .maxlen = sizeof(int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
703 #endif
704 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
706 .ctl_name = KERN_SPIN_RETRY,
707 .procname = "spin_retry",
708 .data = &spin_retry,
709 .maxlen = sizeof (int),
710 .mode = 0644,
711 .proc_handler = &proc_dointvec,
713 #endif
714 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
716 .procname = "acpi_video_flags",
717 .data = &acpi_realmode_flags,
718 .maxlen = sizeof (unsigned long),
719 .mode = 0644,
720 .proc_handler = &proc_doulongvec_minmax,
722 #endif
723 #ifdef CONFIG_IA64
725 .ctl_name = KERN_IA64_UNALIGNED,
726 .procname = "ignore-unaligned-usertrap",
727 .data = &no_unaligned_warning,
728 .maxlen = sizeof (int),
729 .mode = 0644,
730 .proc_handler = &proc_dointvec,
732 #endif
733 #ifdef CONFIG_DETECT_SOFTLOCKUP
735 .ctl_name = CTL_UNNUMBERED,
736 .procname = "softlockup_thresh",
737 .data = &softlockup_thresh,
738 .maxlen = sizeof(unsigned long),
739 .mode = 0644,
740 .proc_handler = &proc_doulongvec_minmax,
741 .strategy = &sysctl_intvec,
742 .extra1 = &one,
743 .extra2 = &sixty,
746 .ctl_name = CTL_UNNUMBERED,
747 .procname = "hung_task_check_count",
748 .data = &sysctl_hung_task_check_count,
749 .maxlen = sizeof(unsigned long),
750 .mode = 0644,
751 .proc_handler = &proc_doulongvec_minmax,
752 .strategy = &sysctl_intvec,
755 .ctl_name = CTL_UNNUMBERED,
756 .procname = "hung_task_timeout_secs",
757 .data = &sysctl_hung_task_timeout_secs,
758 .maxlen = sizeof(unsigned long),
759 .mode = 0644,
760 .proc_handler = &proc_doulongvec_minmax,
761 .strategy = &sysctl_intvec,
764 .ctl_name = CTL_UNNUMBERED,
765 .procname = "hung_task_warnings",
766 .data = &sysctl_hung_task_warnings,
767 .maxlen = sizeof(unsigned long),
768 .mode = 0644,
769 .proc_handler = &proc_doulongvec_minmax,
770 .strategy = &sysctl_intvec,
772 #endif
773 #ifdef CONFIG_COMPAT
775 .ctl_name = KERN_COMPAT_LOG,
776 .procname = "compat-log",
777 .data = &compat_log,
778 .maxlen = sizeof (int),
779 .mode = 0644,
780 .proc_handler = &proc_dointvec,
782 #endif
783 #ifdef CONFIG_RT_MUTEXES
785 .ctl_name = KERN_MAX_LOCK_DEPTH,
786 .procname = "max_lock_depth",
787 .data = &max_lock_depth,
788 .maxlen = sizeof(int),
789 .mode = 0644,
790 .proc_handler = &proc_dointvec,
792 #endif
793 #ifdef CONFIG_PROC_FS
795 .ctl_name = CTL_UNNUMBERED,
796 .procname = "maps_protect",
797 .data = &maps_protect,
798 .maxlen = sizeof(int),
799 .mode = 0644,
800 .proc_handler = &proc_dointvec,
802 #endif
804 .ctl_name = CTL_UNNUMBERED,
805 .procname = "poweroff_cmd",
806 .data = &poweroff_cmd,
807 .maxlen = POWEROFF_CMD_PATH_LEN,
808 .mode = 0644,
809 .proc_handler = &proc_dostring,
810 .strategy = &sysctl_string,
813 * NOTE: do not add new entries to this table unless you have read
814 * Documentation/sysctl/ctl_unnumbered.txt
816 { .ctl_name = 0 }
819 static struct ctl_table vm_table[] = {
821 .ctl_name = VM_OVERCOMMIT_MEMORY,
822 .procname = "overcommit_memory",
823 .data = &sysctl_overcommit_memory,
824 .maxlen = sizeof(sysctl_overcommit_memory),
825 .mode = 0644,
826 .proc_handler = &proc_dointvec,
829 .ctl_name = VM_PANIC_ON_OOM,
830 .procname = "panic_on_oom",
831 .data = &sysctl_panic_on_oom,
832 .maxlen = sizeof(sysctl_panic_on_oom),
833 .mode = 0644,
834 .proc_handler = &proc_dointvec,
837 .ctl_name = CTL_UNNUMBERED,
838 .procname = "oom_kill_allocating_task",
839 .data = &sysctl_oom_kill_allocating_task,
840 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
841 .mode = 0644,
842 .proc_handler = &proc_dointvec,
845 .ctl_name = CTL_UNNUMBERED,
846 .procname = "oom_dump_tasks",
847 .data = &sysctl_oom_dump_tasks,
848 .maxlen = sizeof(sysctl_oom_dump_tasks),
849 .mode = 0644,
850 .proc_handler = &proc_dointvec,
853 .ctl_name = VM_OVERCOMMIT_RATIO,
854 .procname = "overcommit_ratio",
855 .data = &sysctl_overcommit_ratio,
856 .maxlen = sizeof(sysctl_overcommit_ratio),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec,
861 .ctl_name = VM_PAGE_CLUSTER,
862 .procname = "page-cluster",
863 .data = &page_cluster,
864 .maxlen = sizeof(int),
865 .mode = 0644,
866 .proc_handler = &proc_dointvec,
869 .ctl_name = VM_DIRTY_BACKGROUND,
870 .procname = "dirty_background_ratio",
871 .data = &dirty_background_ratio,
872 .maxlen = sizeof(dirty_background_ratio),
873 .mode = 0644,
874 .proc_handler = &proc_dointvec_minmax,
875 .strategy = &sysctl_intvec,
876 .extra1 = &zero,
877 .extra2 = &one_hundred,
880 .ctl_name = VM_DIRTY_RATIO,
881 .procname = "dirty_ratio",
882 .data = &vm_dirty_ratio,
883 .maxlen = sizeof(vm_dirty_ratio),
884 .mode = 0644,
885 .proc_handler = &dirty_ratio_handler,
886 .strategy = &sysctl_intvec,
887 .extra1 = &zero,
888 .extra2 = &one_hundred,
891 .procname = "dirty_writeback_centisecs",
892 .data = &dirty_writeback_interval,
893 .maxlen = sizeof(dirty_writeback_interval),
894 .mode = 0644,
895 .proc_handler = &dirty_writeback_centisecs_handler,
898 .procname = "dirty_expire_centisecs",
899 .data = &dirty_expire_interval,
900 .maxlen = sizeof(dirty_expire_interval),
901 .mode = 0644,
902 .proc_handler = &proc_dointvec_userhz_jiffies,
905 .ctl_name = VM_NR_PDFLUSH_THREADS,
906 .procname = "nr_pdflush_threads",
907 .data = &nr_pdflush_threads,
908 .maxlen = sizeof nr_pdflush_threads,
909 .mode = 0444 /* read-only*/,
910 .proc_handler = &proc_dointvec,
913 .ctl_name = VM_SWAPPINESS,
914 .procname = "swappiness",
915 .data = &vm_swappiness,
916 .maxlen = sizeof(vm_swappiness),
917 .mode = 0644,
918 .proc_handler = &proc_dointvec_minmax,
919 .strategy = &sysctl_intvec,
920 .extra1 = &zero,
921 .extra2 = &one_hundred,
923 #ifdef CONFIG_HUGETLB_PAGE
925 .procname = "nr_hugepages",
926 .data = &max_huge_pages,
927 .maxlen = sizeof(unsigned long),
928 .mode = 0644,
929 .proc_handler = &hugetlb_sysctl_handler,
930 .extra1 = (void *)&hugetlb_zero,
931 .extra2 = (void *)&hugetlb_infinity,
934 .ctl_name = VM_HUGETLB_GROUP,
935 .procname = "hugetlb_shm_group",
936 .data = &sysctl_hugetlb_shm_group,
937 .maxlen = sizeof(gid_t),
938 .mode = 0644,
939 .proc_handler = &proc_dointvec,
942 .ctl_name = CTL_UNNUMBERED,
943 .procname = "hugepages_treat_as_movable",
944 .data = &hugepages_treat_as_movable,
945 .maxlen = sizeof(int),
946 .mode = 0644,
947 .proc_handler = &hugetlb_treat_movable_handler,
950 .ctl_name = CTL_UNNUMBERED,
951 .procname = "nr_overcommit_hugepages",
952 .data = &sysctl_overcommit_huge_pages,
953 .maxlen = sizeof(sysctl_overcommit_huge_pages),
954 .mode = 0644,
955 .proc_handler = &hugetlb_overcommit_handler,
957 #endif
959 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
960 .procname = "lowmem_reserve_ratio",
961 .data = &sysctl_lowmem_reserve_ratio,
962 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
963 .mode = 0644,
964 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
965 .strategy = &sysctl_intvec,
968 .ctl_name = VM_DROP_PAGECACHE,
969 .procname = "drop_caches",
970 .data = &sysctl_drop_caches,
971 .maxlen = sizeof(int),
972 .mode = 0644,
973 .proc_handler = drop_caches_sysctl_handler,
974 .strategy = &sysctl_intvec,
977 .ctl_name = VM_MIN_FREE_KBYTES,
978 .procname = "min_free_kbytes",
979 .data = &min_free_kbytes,
980 .maxlen = sizeof(min_free_kbytes),
981 .mode = 0644,
982 .proc_handler = &min_free_kbytes_sysctl_handler,
983 .strategy = &sysctl_intvec,
984 .extra1 = &zero,
987 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
988 .procname = "percpu_pagelist_fraction",
989 .data = &percpu_pagelist_fraction,
990 .maxlen = sizeof(percpu_pagelist_fraction),
991 .mode = 0644,
992 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
993 .strategy = &sysctl_intvec,
994 .extra1 = &min_percpu_pagelist_fract,
996 #ifdef CONFIG_MMU
998 .ctl_name = VM_MAX_MAP_COUNT,
999 .procname = "max_map_count",
1000 .data = &sysctl_max_map_count,
1001 .maxlen = sizeof(sysctl_max_map_count),
1002 .mode = 0644,
1003 .proc_handler = &proc_dointvec
1005 #endif
1007 .ctl_name = VM_LAPTOP_MODE,
1008 .procname = "laptop_mode",
1009 .data = &laptop_mode,
1010 .maxlen = sizeof(laptop_mode),
1011 .mode = 0644,
1012 .proc_handler = &proc_dointvec_jiffies,
1013 .strategy = &sysctl_jiffies,
1016 .ctl_name = VM_BLOCK_DUMP,
1017 .procname = "block_dump",
1018 .data = &block_dump,
1019 .maxlen = sizeof(block_dump),
1020 .mode = 0644,
1021 .proc_handler = &proc_dointvec,
1022 .strategy = &sysctl_intvec,
1023 .extra1 = &zero,
1026 .ctl_name = VM_VFS_CACHE_PRESSURE,
1027 .procname = "vfs_cache_pressure",
1028 .data = &sysctl_vfs_cache_pressure,
1029 .maxlen = sizeof(sysctl_vfs_cache_pressure),
1030 .mode = 0644,
1031 .proc_handler = &proc_dointvec,
1032 .strategy = &sysctl_intvec,
1033 .extra1 = &zero,
1035 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1037 .ctl_name = VM_LEGACY_VA_LAYOUT,
1038 .procname = "legacy_va_layout",
1039 .data = &sysctl_legacy_va_layout,
1040 .maxlen = sizeof(sysctl_legacy_va_layout),
1041 .mode = 0644,
1042 .proc_handler = &proc_dointvec,
1043 .strategy = &sysctl_intvec,
1044 .extra1 = &zero,
1046 #endif
1047 #ifdef CONFIG_NUMA
1049 .ctl_name = VM_ZONE_RECLAIM_MODE,
1050 .procname = "zone_reclaim_mode",
1051 .data = &zone_reclaim_mode,
1052 .maxlen = sizeof(zone_reclaim_mode),
1053 .mode = 0644,
1054 .proc_handler = &proc_dointvec,
1055 .strategy = &sysctl_intvec,
1056 .extra1 = &zero,
1059 .ctl_name = VM_MIN_UNMAPPED,
1060 .procname = "min_unmapped_ratio",
1061 .data = &sysctl_min_unmapped_ratio,
1062 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1063 .mode = 0644,
1064 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1065 .strategy = &sysctl_intvec,
1066 .extra1 = &zero,
1067 .extra2 = &one_hundred,
1070 .ctl_name = VM_MIN_SLAB,
1071 .procname = "min_slab_ratio",
1072 .data = &sysctl_min_slab_ratio,
1073 .maxlen = sizeof(sysctl_min_slab_ratio),
1074 .mode = 0644,
1075 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1076 .strategy = &sysctl_intvec,
1077 .extra1 = &zero,
1078 .extra2 = &one_hundred,
1080 #endif
1081 #ifdef CONFIG_SMP
1083 .ctl_name = CTL_UNNUMBERED,
1084 .procname = "stat_interval",
1085 .data = &sysctl_stat_interval,
1086 .maxlen = sizeof(sysctl_stat_interval),
1087 .mode = 0644,
1088 .proc_handler = &proc_dointvec_jiffies,
1089 .strategy = &sysctl_jiffies,
1091 #endif
1092 #ifdef CONFIG_SECURITY
1094 .ctl_name = CTL_UNNUMBERED,
1095 .procname = "mmap_min_addr",
1096 .data = &mmap_min_addr,
1097 .maxlen = sizeof(unsigned long),
1098 .mode = 0644,
1099 .proc_handler = &proc_doulongvec_minmax,
1101 #endif
1102 #ifdef CONFIG_NUMA
1104 .ctl_name = CTL_UNNUMBERED,
1105 .procname = "numa_zonelist_order",
1106 .data = &numa_zonelist_order,
1107 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1108 .mode = 0644,
1109 .proc_handler = &numa_zonelist_order_handler,
1110 .strategy = &sysctl_string,
1112 #endif
1113 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1114 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1116 .ctl_name = VM_VDSO_ENABLED,
1117 .procname = "vdso_enabled",
1118 .data = &vdso_enabled,
1119 .maxlen = sizeof(vdso_enabled),
1120 .mode = 0644,
1121 .proc_handler = &proc_dointvec,
1122 .strategy = &sysctl_intvec,
1123 .extra1 = &zero,
1125 #endif
1126 #ifdef CONFIG_HIGHMEM
1128 .ctl_name = CTL_UNNUMBERED,
1129 .procname = "highmem_is_dirtyable",
1130 .data = &vm_highmem_is_dirtyable,
1131 .maxlen = sizeof(vm_highmem_is_dirtyable),
1132 .mode = 0644,
1133 .proc_handler = &proc_dointvec_minmax,
1134 .strategy = &sysctl_intvec,
1135 .extra1 = &zero,
1136 .extra2 = &one,
1138 #endif
1140 * NOTE: do not add new entries to this table unless you have read
1141 * Documentation/sysctl/ctl_unnumbered.txt
1143 { .ctl_name = 0 }
1146 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1147 static struct ctl_table binfmt_misc_table[] = {
1148 { .ctl_name = 0 }
1150 #endif
1152 static struct ctl_table fs_table[] = {
1154 .ctl_name = FS_NRINODE,
1155 .procname = "inode-nr",
1156 .data = &inodes_stat,
1157 .maxlen = 2*sizeof(int),
1158 .mode = 0444,
1159 .proc_handler = &proc_dointvec,
1162 .ctl_name = FS_STATINODE,
1163 .procname = "inode-state",
1164 .data = &inodes_stat,
1165 .maxlen = 7*sizeof(int),
1166 .mode = 0444,
1167 .proc_handler = &proc_dointvec,
1170 .procname = "file-nr",
1171 .data = &files_stat,
1172 .maxlen = 3*sizeof(int),
1173 .mode = 0444,
1174 .proc_handler = &proc_nr_files,
1177 .ctl_name = FS_MAXFILE,
1178 .procname = "file-max",
1179 .data = &files_stat.max_files,
1180 .maxlen = sizeof(int),
1181 .mode = 0644,
1182 .proc_handler = &proc_dointvec,
1185 .ctl_name = CTL_UNNUMBERED,
1186 .procname = "nr_open",
1187 .data = &sysctl_nr_open,
1188 .maxlen = sizeof(int),
1189 .mode = 0644,
1190 .proc_handler = &proc_dointvec,
1193 .ctl_name = FS_DENTRY,
1194 .procname = "dentry-state",
1195 .data = &dentry_stat,
1196 .maxlen = 6*sizeof(int),
1197 .mode = 0444,
1198 .proc_handler = &proc_dointvec,
1201 .ctl_name = FS_OVERFLOWUID,
1202 .procname = "overflowuid",
1203 .data = &fs_overflowuid,
1204 .maxlen = sizeof(int),
1205 .mode = 0644,
1206 .proc_handler = &proc_dointvec_minmax,
1207 .strategy = &sysctl_intvec,
1208 .extra1 = &minolduid,
1209 .extra2 = &maxolduid,
1212 .ctl_name = FS_OVERFLOWGID,
1213 .procname = "overflowgid",
1214 .data = &fs_overflowgid,
1215 .maxlen = sizeof(int),
1216 .mode = 0644,
1217 .proc_handler = &proc_dointvec_minmax,
1218 .strategy = &sysctl_intvec,
1219 .extra1 = &minolduid,
1220 .extra2 = &maxolduid,
1223 .ctl_name = FS_LEASES,
1224 .procname = "leases-enable",
1225 .data = &leases_enable,
1226 .maxlen = sizeof(int),
1227 .mode = 0644,
1228 .proc_handler = &proc_dointvec,
1230 #ifdef CONFIG_DNOTIFY
1232 .ctl_name = FS_DIR_NOTIFY,
1233 .procname = "dir-notify-enable",
1234 .data = &dir_notify_enable,
1235 .maxlen = sizeof(int),
1236 .mode = 0644,
1237 .proc_handler = &proc_dointvec,
1239 #endif
1240 #ifdef CONFIG_MMU
1242 .ctl_name = FS_LEASE_TIME,
1243 .procname = "lease-break-time",
1244 .data = &lease_break_time,
1245 .maxlen = sizeof(int),
1246 .mode = 0644,
1247 .proc_handler = &proc_dointvec_minmax,
1248 .strategy = &sysctl_intvec,
1249 .extra1 = &zero,
1250 .extra2 = &two,
1253 .procname = "aio-nr",
1254 .data = &aio_nr,
1255 .maxlen = sizeof(aio_nr),
1256 .mode = 0444,
1257 .proc_handler = &proc_doulongvec_minmax,
1260 .procname = "aio-max-nr",
1261 .data = &aio_max_nr,
1262 .maxlen = sizeof(aio_max_nr),
1263 .mode = 0644,
1264 .proc_handler = &proc_doulongvec_minmax,
1266 #ifdef CONFIG_INOTIFY_USER
1268 .ctl_name = FS_INOTIFY,
1269 .procname = "inotify",
1270 .mode = 0555,
1271 .child = inotify_table,
1273 #endif
1274 #endif
1276 .ctl_name = KERN_SETUID_DUMPABLE,
1277 .procname = "suid_dumpable",
1278 .data = &suid_dumpable,
1279 .maxlen = sizeof(int),
1280 .mode = 0644,
1281 .proc_handler = &proc_dointvec,
1283 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1285 .ctl_name = CTL_UNNUMBERED,
1286 .procname = "binfmt_misc",
1287 .mode = 0555,
1288 .child = binfmt_misc_table,
1290 #endif
1292 * NOTE: do not add new entries to this table unless you have read
1293 * Documentation/sysctl/ctl_unnumbered.txt
1295 { .ctl_name = 0 }
1298 static struct ctl_table debug_table[] = {
1299 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1301 .ctl_name = CTL_UNNUMBERED,
1302 .procname = "exception-trace",
1303 .data = &show_unhandled_signals,
1304 .maxlen = sizeof(int),
1305 .mode = 0644,
1306 .proc_handler = proc_dointvec
1308 #endif
1309 { .ctl_name = 0 }
1312 static struct ctl_table dev_table[] = {
1313 { .ctl_name = 0 }
1316 static DEFINE_SPINLOCK(sysctl_lock);
1318 /* called under sysctl_lock */
1319 static int use_table(struct ctl_table_header *p)
1321 if (unlikely(p->unregistering))
1322 return 0;
1323 p->used++;
1324 return 1;
1327 /* called under sysctl_lock */
1328 static void unuse_table(struct ctl_table_header *p)
1330 if (!--p->used)
1331 if (unlikely(p->unregistering))
1332 complete(p->unregistering);
1335 /* called under sysctl_lock, will reacquire if has to wait */
1336 static void start_unregistering(struct ctl_table_header *p)
1339 * if p->used is 0, nobody will ever touch that entry again;
1340 * we'll eliminate all paths to it before dropping sysctl_lock
1342 if (unlikely(p->used)) {
1343 struct completion wait;
1344 init_completion(&wait);
1345 p->unregistering = &wait;
1346 spin_unlock(&sysctl_lock);
1347 wait_for_completion(&wait);
1348 spin_lock(&sysctl_lock);
1351 * do not remove from the list until nobody holds it; walking the
1352 * list in do_sysctl() relies on that.
1354 list_del_init(&p->ctl_entry);
1357 void sysctl_head_finish(struct ctl_table_header *head)
1359 if (!head)
1360 return;
1361 spin_lock(&sysctl_lock);
1362 unuse_table(head);
1363 spin_unlock(&sysctl_lock);
1366 static struct list_head *
1367 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1369 struct list_head *header_list;
1370 header_list = &root->header_list;
1371 if (root->lookup)
1372 header_list = root->lookup(root, namespaces);
1373 return header_list;
1376 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1377 struct ctl_table_header *prev)
1379 struct ctl_table_root *root;
1380 struct list_head *header_list;
1381 struct ctl_table_header *head;
1382 struct list_head *tmp;
1384 spin_lock(&sysctl_lock);
1385 if (prev) {
1386 head = prev;
1387 tmp = &prev->ctl_entry;
1388 unuse_table(prev);
1389 goto next;
1391 tmp = &root_table_header.ctl_entry;
1392 for (;;) {
1393 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1395 if (!use_table(head))
1396 goto next;
1397 spin_unlock(&sysctl_lock);
1398 return head;
1399 next:
1400 root = head->root;
1401 tmp = tmp->next;
1402 header_list = lookup_header_list(root, namespaces);
1403 if (tmp != header_list)
1404 continue;
1406 do {
1407 root = list_entry(root->root_list.next,
1408 struct ctl_table_root, root_list);
1409 if (root == &sysctl_table_root)
1410 goto out;
1411 header_list = lookup_header_list(root, namespaces);
1412 } while (list_empty(header_list));
1413 tmp = header_list->next;
1415 out:
1416 spin_unlock(&sysctl_lock);
1417 return NULL;
1420 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1422 return __sysctl_head_next(current->nsproxy, prev);
1425 void register_sysctl_root(struct ctl_table_root *root)
1427 spin_lock(&sysctl_lock);
1428 list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1429 spin_unlock(&sysctl_lock);
1432 #ifdef CONFIG_SYSCTL_SYSCALL
1433 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1434 void __user *newval, size_t newlen)
1436 struct ctl_table_header *head;
1437 int error = -ENOTDIR;
1439 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1440 return -ENOTDIR;
1441 if (oldval) {
1442 int old_len;
1443 if (!oldlenp || get_user(old_len, oldlenp))
1444 return -EFAULT;
1447 for (head = sysctl_head_next(NULL); head;
1448 head = sysctl_head_next(head)) {
1449 error = parse_table(name, nlen, oldval, oldlenp,
1450 newval, newlen, head->ctl_table);
1451 if (error != -ENOTDIR) {
1452 sysctl_head_finish(head);
1453 break;
1456 return error;
1459 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1461 struct __sysctl_args tmp;
1462 int error;
1464 if (copy_from_user(&tmp, args, sizeof(tmp)))
1465 return -EFAULT;
1467 error = deprecated_sysctl_warning(&tmp);
1468 if (error)
1469 goto out;
1471 lock_kernel();
1472 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1473 tmp.newval, tmp.newlen);
1474 unlock_kernel();
1475 out:
1476 return error;
1478 #endif /* CONFIG_SYSCTL_SYSCALL */
1481 * sysctl_perm does NOT grant the superuser all rights automatically, because
1482 * some sysctl variables are readonly even to root.
1485 static int test_perm(int mode, int op)
1487 if (!current->euid)
1488 mode >>= 6;
1489 else if (in_egroup_p(0))
1490 mode >>= 3;
1491 if ((mode & op & 0007) == op)
1492 return 0;
1493 return -EACCES;
1496 int sysctl_perm(struct ctl_table *table, int op)
1498 int error;
1499 error = security_sysctl(table, op);
1500 if (error)
1501 return error;
1502 return test_perm(table->mode, op);
1505 #ifdef CONFIG_SYSCTL_SYSCALL
1506 static int parse_table(int __user *name, int nlen,
1507 void __user *oldval, size_t __user *oldlenp,
1508 void __user *newval, size_t newlen,
1509 struct ctl_table *table)
1511 int n;
1512 repeat:
1513 if (!nlen)
1514 return -ENOTDIR;
1515 if (get_user(n, name))
1516 return -EFAULT;
1517 for ( ; table->ctl_name || table->procname; table++) {
1518 if (!table->ctl_name)
1519 continue;
1520 if (n == table->ctl_name) {
1521 int error;
1522 if (table->child) {
1523 if (sysctl_perm(table, 001))
1524 return -EPERM;
1525 name++;
1526 nlen--;
1527 table = table->child;
1528 goto repeat;
1530 error = do_sysctl_strategy(table, name, nlen,
1531 oldval, oldlenp,
1532 newval, newlen);
1533 return error;
1536 return -ENOTDIR;
1539 /* Perform the actual read/write of a sysctl table entry. */
1540 int do_sysctl_strategy (struct ctl_table *table,
1541 int __user *name, int nlen,
1542 void __user *oldval, size_t __user *oldlenp,
1543 void __user *newval, size_t newlen)
1545 int op = 0, rc;
1547 if (oldval)
1548 op |= 004;
1549 if (newval)
1550 op |= 002;
1551 if (sysctl_perm(table, op))
1552 return -EPERM;
1554 if (table->strategy) {
1555 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1556 newval, newlen);
1557 if (rc < 0)
1558 return rc;
1559 if (rc > 0)
1560 return 0;
1563 /* If there is no strategy routine, or if the strategy returns
1564 * zero, proceed with automatic r/w */
1565 if (table->data && table->maxlen) {
1566 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1567 newval, newlen);
1568 if (rc < 0)
1569 return rc;
1571 return 0;
1573 #endif /* CONFIG_SYSCTL_SYSCALL */
1575 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1577 for (; table->ctl_name || table->procname; table++) {
1578 table->parent = parent;
1579 if (table->child)
1580 sysctl_set_parent(table, table->child);
1584 static __init int sysctl_init(void)
1586 int err;
1587 sysctl_set_parent(NULL, root_table);
1588 err = sysctl_check_table(current->nsproxy, root_table);
1589 return 0;
1592 core_initcall(sysctl_init);
1595 * __register_sysctl_paths - register a sysctl hierarchy
1596 * @root: List of sysctl headers to register on
1597 * @namespaces: Data to compute which lists of sysctl entries are visible
1598 * @path: The path to the directory the sysctl table is in.
1599 * @table: the top-level table structure
1601 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1602 * array. A completely 0 filled entry terminates the table.
1604 * The members of the &struct ctl_table structure are used as follows:
1606 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1607 * must be unique within that level of sysctl
1609 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1610 * enter a sysctl file
1612 * data - a pointer to data for use by proc_handler
1614 * maxlen - the maximum size in bytes of the data
1616 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1618 * child - a pointer to the child sysctl table if this entry is a directory, or
1619 * %NULL.
1621 * proc_handler - the text handler routine (described below)
1623 * strategy - the strategy routine (described below)
1625 * de - for internal use by the sysctl routines
1627 * extra1, extra2 - extra pointers usable by the proc handler routines
1629 * Leaf nodes in the sysctl tree will be represented by a single file
1630 * under /proc; non-leaf nodes will be represented by directories.
1632 * sysctl(2) can automatically manage read and write requests through
1633 * the sysctl table. The data and maxlen fields of the ctl_table
1634 * struct enable minimal validation of the values being written to be
1635 * performed, and the mode field allows minimal authentication.
1637 * More sophisticated management can be enabled by the provision of a
1638 * strategy routine with the table entry. This will be called before
1639 * any automatic read or write of the data is performed.
1641 * The strategy routine may return
1643 * < 0 - Error occurred (error is passed to user process)
1645 * 0 - OK - proceed with automatic read or write.
1647 * > 0 - OK - read or write has been done by the strategy routine, so
1648 * return immediately.
1650 * There must be a proc_handler routine for any terminal nodes
1651 * mirrored under /proc/sys (non-terminals are handled by a built-in
1652 * directory handler). Several default handlers are available to
1653 * cover common cases -
1655 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1656 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1657 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1659 * It is the handler's job to read the input buffer from user memory
1660 * and process it. The handler should return 0 on success.
1662 * This routine returns %NULL on a failure to register, and a pointer
1663 * to the table header on success.
1665 struct ctl_table_header *__register_sysctl_paths(
1666 struct ctl_table_root *root,
1667 struct nsproxy *namespaces,
1668 const struct ctl_path *path, struct ctl_table *table)
1670 struct list_head *header_list;
1671 struct ctl_table_header *header;
1672 struct ctl_table *new, **prevp;
1673 unsigned int n, npath;
1675 /* Count the path components */
1676 for (npath = 0; path[npath].ctl_name || path[npath].procname; ++npath)
1680 * For each path component, allocate a 2-element ctl_table array.
1681 * The first array element will be filled with the sysctl entry
1682 * for this, the second will be the sentinel (ctl_name == 0).
1684 * We allocate everything in one go so that we don't have to
1685 * worry about freeing additional memory in unregister_sysctl_table.
1687 header = kzalloc(sizeof(struct ctl_table_header) +
1688 (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1689 if (!header)
1690 return NULL;
1692 new = (struct ctl_table *) (header + 1);
1694 /* Now connect the dots */
1695 prevp = &header->ctl_table;
1696 for (n = 0; n < npath; ++n, ++path) {
1697 /* Copy the procname */
1698 new->procname = path->procname;
1699 new->ctl_name = path->ctl_name;
1700 new->mode = 0555;
1702 *prevp = new;
1703 prevp = &new->child;
1705 new += 2;
1707 *prevp = table;
1708 header->ctl_table_arg = table;
1710 INIT_LIST_HEAD(&header->ctl_entry);
1711 header->used = 0;
1712 header->unregistering = NULL;
1713 header->root = root;
1714 sysctl_set_parent(NULL, header->ctl_table);
1715 if (sysctl_check_table(namespaces, header->ctl_table)) {
1716 kfree(header);
1717 return NULL;
1719 spin_lock(&sysctl_lock);
1720 header_list = lookup_header_list(root, namespaces);
1721 list_add_tail(&header->ctl_entry, header_list);
1722 spin_unlock(&sysctl_lock);
1724 return header;
1728 * register_sysctl_table_path - register a sysctl table hierarchy
1729 * @path: The path to the directory the sysctl table is in.
1730 * @table: the top-level table structure
1732 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1733 * array. A completely 0 filled entry terminates the table.
1735 * See __register_sysctl_paths for more details.
1737 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1738 struct ctl_table *table)
1740 return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1741 path, table);
1745 * register_sysctl_table - register a sysctl table hierarchy
1746 * @table: the top-level table structure
1748 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1749 * array. A completely 0 filled entry terminates the table.
1751 * See register_sysctl_paths for more details.
1753 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1755 static const struct ctl_path null_path[] = { {} };
1757 return register_sysctl_paths(null_path, table);
1761 * unregister_sysctl_table - unregister a sysctl table hierarchy
1762 * @header: the header returned from register_sysctl_table
1764 * Unregisters the sysctl table and all children. proc entries may not
1765 * actually be removed until they are no longer used by anyone.
1767 void unregister_sysctl_table(struct ctl_table_header * header)
1769 might_sleep();
1771 if (header == NULL)
1772 return;
1774 spin_lock(&sysctl_lock);
1775 start_unregistering(header);
1776 spin_unlock(&sysctl_lock);
1777 kfree(header);
1780 #else /* !CONFIG_SYSCTL */
1781 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1783 return NULL;
1786 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1787 struct ctl_table *table)
1789 return NULL;
1792 void unregister_sysctl_table(struct ctl_table_header * table)
1796 #endif /* CONFIG_SYSCTL */
1799 * /proc/sys support
1802 #ifdef CONFIG_PROC_SYSCTL
1804 static int _proc_do_string(void* data, int maxlen, int write,
1805 struct file *filp, void __user *buffer,
1806 size_t *lenp, loff_t *ppos)
1808 size_t len;
1809 char __user *p;
1810 char c;
1812 if (!data || !maxlen || !*lenp) {
1813 *lenp = 0;
1814 return 0;
1817 if (write) {
1818 len = 0;
1819 p = buffer;
1820 while (len < *lenp) {
1821 if (get_user(c, p++))
1822 return -EFAULT;
1823 if (c == 0 || c == '\n')
1824 break;
1825 len++;
1827 if (len >= maxlen)
1828 len = maxlen-1;
1829 if(copy_from_user(data, buffer, len))
1830 return -EFAULT;
1831 ((char *) data)[len] = 0;
1832 *ppos += *lenp;
1833 } else {
1834 len = strlen(data);
1835 if (len > maxlen)
1836 len = maxlen;
1838 if (*ppos > len) {
1839 *lenp = 0;
1840 return 0;
1843 data += *ppos;
1844 len -= *ppos;
1846 if (len > *lenp)
1847 len = *lenp;
1848 if (len)
1849 if(copy_to_user(buffer, data, len))
1850 return -EFAULT;
1851 if (len < *lenp) {
1852 if(put_user('\n', ((char __user *) buffer) + len))
1853 return -EFAULT;
1854 len++;
1856 *lenp = len;
1857 *ppos += len;
1859 return 0;
1863 * proc_dostring - read a string sysctl
1864 * @table: the sysctl table
1865 * @write: %TRUE if this is a write to the sysctl file
1866 * @filp: the file structure
1867 * @buffer: the user buffer
1868 * @lenp: the size of the user buffer
1869 * @ppos: file position
1871 * Reads/writes a string from/to the user buffer. If the kernel
1872 * buffer provided is not large enough to hold the string, the
1873 * string is truncated. The copied string is %NULL-terminated.
1874 * If the string is being read by the user process, it is copied
1875 * and a newline '\n' is added. It is truncated if the buffer is
1876 * not large enough.
1878 * Returns 0 on success.
1880 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1881 void __user *buffer, size_t *lenp, loff_t *ppos)
1883 return _proc_do_string(table->data, table->maxlen, write, filp,
1884 buffer, lenp, ppos);
1888 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1889 int *valp,
1890 int write, void *data)
1892 if (write) {
1893 *valp = *negp ? -*lvalp : *lvalp;
1894 } else {
1895 int val = *valp;
1896 if (val < 0) {
1897 *negp = -1;
1898 *lvalp = (unsigned long)-val;
1899 } else {
1900 *negp = 0;
1901 *lvalp = (unsigned long)val;
1904 return 0;
1907 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1908 int write, struct file *filp, void __user *buffer,
1909 size_t *lenp, loff_t *ppos,
1910 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1911 int write, void *data),
1912 void *data)
1914 #define TMPBUFLEN 21
1915 int *i, vleft, first=1, neg, val;
1916 unsigned long lval;
1917 size_t left, len;
1919 char buf[TMPBUFLEN], *p;
1920 char __user *s = buffer;
1922 if (!tbl_data || !table->maxlen || !*lenp ||
1923 (*ppos && !write)) {
1924 *lenp = 0;
1925 return 0;
1928 i = (int *) tbl_data;
1929 vleft = table->maxlen / sizeof(*i);
1930 left = *lenp;
1932 if (!conv)
1933 conv = do_proc_dointvec_conv;
1935 for (; left && vleft--; i++, first=0) {
1936 if (write) {
1937 while (left) {
1938 char c;
1939 if (get_user(c, s))
1940 return -EFAULT;
1941 if (!isspace(c))
1942 break;
1943 left--;
1944 s++;
1946 if (!left)
1947 break;
1948 neg = 0;
1949 len = left;
1950 if (len > sizeof(buf) - 1)
1951 len = sizeof(buf) - 1;
1952 if (copy_from_user(buf, s, len))
1953 return -EFAULT;
1954 buf[len] = 0;
1955 p = buf;
1956 if (*p == '-' && left > 1) {
1957 neg = 1;
1958 p++;
1960 if (*p < '0' || *p > '9')
1961 break;
1963 lval = simple_strtoul(p, &p, 0);
1965 len = p-buf;
1966 if ((len < left) && *p && !isspace(*p))
1967 break;
1968 if (neg)
1969 val = -val;
1970 s += len;
1971 left -= len;
1973 if (conv(&neg, &lval, i, 1, data))
1974 break;
1975 } else {
1976 p = buf;
1977 if (!first)
1978 *p++ = '\t';
1980 if (conv(&neg, &lval, i, 0, data))
1981 break;
1983 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1984 len = strlen(buf);
1985 if (len > left)
1986 len = left;
1987 if(copy_to_user(s, buf, len))
1988 return -EFAULT;
1989 left -= len;
1990 s += len;
1994 if (!write && !first && left) {
1995 if(put_user('\n', s))
1996 return -EFAULT;
1997 left--, s++;
1999 if (write) {
2000 while (left) {
2001 char c;
2002 if (get_user(c, s++))
2003 return -EFAULT;
2004 if (!isspace(c))
2005 break;
2006 left--;
2009 if (write && first)
2010 return -EINVAL;
2011 *lenp -= left;
2012 *ppos += *lenp;
2013 return 0;
2014 #undef TMPBUFLEN
2017 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2018 void __user *buffer, size_t *lenp, loff_t *ppos,
2019 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
2020 int write, void *data),
2021 void *data)
2023 return __do_proc_dointvec(table->data, table, write, filp,
2024 buffer, lenp, ppos, conv, data);
2028 * proc_dointvec - read a vector of integers
2029 * @table: the sysctl table
2030 * @write: %TRUE if this is a write to the sysctl file
2031 * @filp: the file structure
2032 * @buffer: the user buffer
2033 * @lenp: the size of the user buffer
2034 * @ppos: file position
2036 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2037 * values from/to the user buffer, treated as an ASCII string.
2039 * Returns 0 on success.
2041 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2042 void __user *buffer, size_t *lenp, loff_t *ppos)
2044 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2045 NULL,NULL);
2048 #define OP_SET 0
2049 #define OP_AND 1
2050 #define OP_OR 2
2052 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
2053 int *valp,
2054 int write, void *data)
2056 int op = *(int *)data;
2057 if (write) {
2058 int val = *negp ? -*lvalp : *lvalp;
2059 switch(op) {
2060 case OP_SET: *valp = val; break;
2061 case OP_AND: *valp &= val; break;
2062 case OP_OR: *valp |= val; break;
2064 } else {
2065 int val = *valp;
2066 if (val < 0) {
2067 *negp = -1;
2068 *lvalp = (unsigned long)-val;
2069 } else {
2070 *negp = 0;
2071 *lvalp = (unsigned long)val;
2074 return 0;
2078 * Taint values can only be increased
2080 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
2081 void __user *buffer, size_t *lenp, loff_t *ppos)
2083 int op;
2085 if (write && !capable(CAP_SYS_ADMIN))
2086 return -EPERM;
2088 op = OP_OR;
2089 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2090 do_proc_dointvec_bset_conv,&op);
2093 struct do_proc_dointvec_minmax_conv_param {
2094 int *min;
2095 int *max;
2098 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
2099 int *valp,
2100 int write, void *data)
2102 struct do_proc_dointvec_minmax_conv_param *param = data;
2103 if (write) {
2104 int val = *negp ? -*lvalp : *lvalp;
2105 if ((param->min && *param->min > val) ||
2106 (param->max && *param->max < val))
2107 return -EINVAL;
2108 *valp = val;
2109 } else {
2110 int val = *valp;
2111 if (val < 0) {
2112 *negp = -1;
2113 *lvalp = (unsigned long)-val;
2114 } else {
2115 *negp = 0;
2116 *lvalp = (unsigned long)val;
2119 return 0;
2123 * proc_dointvec_minmax - read a vector of integers with min/max values
2124 * @table: the sysctl table
2125 * @write: %TRUE if this is a write to the sysctl file
2126 * @filp: the file structure
2127 * @buffer: the user buffer
2128 * @lenp: the size of the user buffer
2129 * @ppos: file position
2131 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2132 * values from/to the user buffer, treated as an ASCII string.
2134 * This routine will ensure the values are within the range specified by
2135 * table->extra1 (min) and table->extra2 (max).
2137 * Returns 0 on success.
2139 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2140 void __user *buffer, size_t *lenp, loff_t *ppos)
2142 struct do_proc_dointvec_minmax_conv_param param = {
2143 .min = (int *) table->extra1,
2144 .max = (int *) table->extra2,
2146 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2147 do_proc_dointvec_minmax_conv, &param);
2150 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2151 struct file *filp,
2152 void __user *buffer,
2153 size_t *lenp, loff_t *ppos,
2154 unsigned long convmul,
2155 unsigned long convdiv)
2157 #define TMPBUFLEN 21
2158 unsigned long *i, *min, *max, val;
2159 int vleft, first=1, neg;
2160 size_t len, left;
2161 char buf[TMPBUFLEN], *p;
2162 char __user *s = buffer;
2164 if (!data || !table->maxlen || !*lenp ||
2165 (*ppos && !write)) {
2166 *lenp = 0;
2167 return 0;
2170 i = (unsigned long *) data;
2171 min = (unsigned long *) table->extra1;
2172 max = (unsigned long *) table->extra2;
2173 vleft = table->maxlen / sizeof(unsigned long);
2174 left = *lenp;
2176 for (; left && vleft--; i++, min++, max++, first=0) {
2177 if (write) {
2178 while (left) {
2179 char c;
2180 if (get_user(c, s))
2181 return -EFAULT;
2182 if (!isspace(c))
2183 break;
2184 left--;
2185 s++;
2187 if (!left)
2188 break;
2189 neg = 0;
2190 len = left;
2191 if (len > TMPBUFLEN-1)
2192 len = TMPBUFLEN-1;
2193 if (copy_from_user(buf, s, len))
2194 return -EFAULT;
2195 buf[len] = 0;
2196 p = buf;
2197 if (*p == '-' && left > 1) {
2198 neg = 1;
2199 p++;
2201 if (*p < '0' || *p > '9')
2202 break;
2203 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2204 len = p-buf;
2205 if ((len < left) && *p && !isspace(*p))
2206 break;
2207 if (neg)
2208 val = -val;
2209 s += len;
2210 left -= len;
2212 if(neg)
2213 continue;
2214 if ((min && val < *min) || (max && val > *max))
2215 continue;
2216 *i = val;
2217 } else {
2218 p = buf;
2219 if (!first)
2220 *p++ = '\t';
2221 sprintf(p, "%lu", convdiv * (*i) / convmul);
2222 len = strlen(buf);
2223 if (len > left)
2224 len = left;
2225 if(copy_to_user(s, buf, len))
2226 return -EFAULT;
2227 left -= len;
2228 s += len;
2232 if (!write && !first && left) {
2233 if(put_user('\n', s))
2234 return -EFAULT;
2235 left--, s++;
2237 if (write) {
2238 while (left) {
2239 char c;
2240 if (get_user(c, s++))
2241 return -EFAULT;
2242 if (!isspace(c))
2243 break;
2244 left--;
2247 if (write && first)
2248 return -EINVAL;
2249 *lenp -= left;
2250 *ppos += *lenp;
2251 return 0;
2252 #undef TMPBUFLEN
2255 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2256 struct file *filp,
2257 void __user *buffer,
2258 size_t *lenp, loff_t *ppos,
2259 unsigned long convmul,
2260 unsigned long convdiv)
2262 return __do_proc_doulongvec_minmax(table->data, table, write,
2263 filp, buffer, lenp, ppos, convmul, convdiv);
2267 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2268 * @table: the sysctl table
2269 * @write: %TRUE if this is a write to the sysctl file
2270 * @filp: the file structure
2271 * @buffer: the user buffer
2272 * @lenp: the size of the user buffer
2273 * @ppos: file position
2275 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2276 * values from/to the user buffer, treated as an ASCII string.
2278 * This routine will ensure the values are within the range specified by
2279 * table->extra1 (min) and table->extra2 (max).
2281 * Returns 0 on success.
2283 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2284 void __user *buffer, size_t *lenp, loff_t *ppos)
2286 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2290 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2291 * @table: the sysctl table
2292 * @write: %TRUE if this is a write to the sysctl file
2293 * @filp: the file structure
2294 * @buffer: the user buffer
2295 * @lenp: the size of the user buffer
2296 * @ppos: file position
2298 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2299 * values from/to the user buffer, treated as an ASCII string. The values
2300 * are treated as milliseconds, and converted to jiffies when they are stored.
2302 * This routine will ensure the values are within the range specified by
2303 * table->extra1 (min) and table->extra2 (max).
2305 * Returns 0 on success.
2307 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2308 struct file *filp,
2309 void __user *buffer,
2310 size_t *lenp, loff_t *ppos)
2312 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2313 lenp, ppos, HZ, 1000l);
2317 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2318 int *valp,
2319 int write, void *data)
2321 if (write) {
2322 if (*lvalp > LONG_MAX / HZ)
2323 return 1;
2324 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2325 } else {
2326 int val = *valp;
2327 unsigned long lval;
2328 if (val < 0) {
2329 *negp = -1;
2330 lval = (unsigned long)-val;
2331 } else {
2332 *negp = 0;
2333 lval = (unsigned long)val;
2335 *lvalp = lval / HZ;
2337 return 0;
2340 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2341 int *valp,
2342 int write, void *data)
2344 if (write) {
2345 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2346 return 1;
2347 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2348 } else {
2349 int val = *valp;
2350 unsigned long lval;
2351 if (val < 0) {
2352 *negp = -1;
2353 lval = (unsigned long)-val;
2354 } else {
2355 *negp = 0;
2356 lval = (unsigned long)val;
2358 *lvalp = jiffies_to_clock_t(lval);
2360 return 0;
2363 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2364 int *valp,
2365 int write, void *data)
2367 if (write) {
2368 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2369 } else {
2370 int val = *valp;
2371 unsigned long lval;
2372 if (val < 0) {
2373 *negp = -1;
2374 lval = (unsigned long)-val;
2375 } else {
2376 *negp = 0;
2377 lval = (unsigned long)val;
2379 *lvalp = jiffies_to_msecs(lval);
2381 return 0;
2385 * proc_dointvec_jiffies - read a vector of integers as seconds
2386 * @table: the sysctl table
2387 * @write: %TRUE if this is a write to the sysctl file
2388 * @filp: the file structure
2389 * @buffer: the user buffer
2390 * @lenp: the size of the user buffer
2391 * @ppos: file position
2393 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2394 * values from/to the user buffer, treated as an ASCII string.
2395 * The values read are assumed to be in seconds, and are converted into
2396 * jiffies.
2398 * Returns 0 on success.
2400 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2401 void __user *buffer, size_t *lenp, loff_t *ppos)
2403 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2404 do_proc_dointvec_jiffies_conv,NULL);
2408 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2409 * @table: the sysctl table
2410 * @write: %TRUE if this is a write to the sysctl file
2411 * @filp: the file structure
2412 * @buffer: the user buffer
2413 * @lenp: the size of the user buffer
2414 * @ppos: pointer to the file position
2416 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2417 * values from/to the user buffer, treated as an ASCII string.
2418 * The values read are assumed to be in 1/USER_HZ seconds, and
2419 * are converted into jiffies.
2421 * Returns 0 on success.
2423 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2424 void __user *buffer, size_t *lenp, loff_t *ppos)
2426 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2427 do_proc_dointvec_userhz_jiffies_conv,NULL);
2431 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2432 * @table: the sysctl table
2433 * @write: %TRUE if this is a write to the sysctl file
2434 * @filp: the file structure
2435 * @buffer: the user buffer
2436 * @lenp: the size of the user buffer
2437 * @ppos: file position
2438 * @ppos: the current position in the file
2440 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2441 * values from/to the user buffer, treated as an ASCII string.
2442 * The values read are assumed to be in 1/1000 seconds, and
2443 * are converted into jiffies.
2445 * Returns 0 on success.
2447 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2448 void __user *buffer, size_t *lenp, loff_t *ppos)
2450 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2451 do_proc_dointvec_ms_jiffies_conv, NULL);
2454 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2455 void __user *buffer, size_t *lenp, loff_t *ppos)
2457 struct pid *new_pid;
2458 pid_t tmp;
2459 int r;
2461 tmp = pid_vnr(cad_pid);
2463 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2464 lenp, ppos, NULL, NULL);
2465 if (r || !write)
2466 return r;
2468 new_pid = find_get_pid(tmp);
2469 if (!new_pid)
2470 return -ESRCH;
2472 put_pid(xchg(&cad_pid, new_pid));
2473 return 0;
2476 #else /* CONFIG_PROC_FS */
2478 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2479 void __user *buffer, size_t *lenp, loff_t *ppos)
2481 return -ENOSYS;
2484 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2485 void __user *buffer, size_t *lenp, loff_t *ppos)
2487 return -ENOSYS;
2490 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2491 void __user *buffer, size_t *lenp, loff_t *ppos)
2493 return -ENOSYS;
2496 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2497 void __user *buffer, size_t *lenp, loff_t *ppos)
2499 return -ENOSYS;
2502 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2503 void __user *buffer, size_t *lenp, loff_t *ppos)
2505 return -ENOSYS;
2508 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2509 void __user *buffer, size_t *lenp, loff_t *ppos)
2511 return -ENOSYS;
2514 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2515 void __user *buffer, size_t *lenp, loff_t *ppos)
2517 return -ENOSYS;
2520 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2521 struct file *filp,
2522 void __user *buffer,
2523 size_t *lenp, loff_t *ppos)
2525 return -ENOSYS;
2529 #endif /* CONFIG_PROC_FS */
2532 #ifdef CONFIG_SYSCTL_SYSCALL
2534 * General sysctl support routines
2537 /* The generic sysctl data routine (used if no strategy routine supplied) */
2538 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2539 void __user *oldval, size_t __user *oldlenp,
2540 void __user *newval, size_t newlen)
2542 size_t len;
2544 /* Get out of I don't have a variable */
2545 if (!table->data || !table->maxlen)
2546 return -ENOTDIR;
2548 if (oldval && oldlenp) {
2549 if (get_user(len, oldlenp))
2550 return -EFAULT;
2551 if (len) {
2552 if (len > table->maxlen)
2553 len = table->maxlen;
2554 if (copy_to_user(oldval, table->data, len))
2555 return -EFAULT;
2556 if (put_user(len, oldlenp))
2557 return -EFAULT;
2561 if (newval && newlen) {
2562 if (newlen > table->maxlen)
2563 newlen = table->maxlen;
2565 if (copy_from_user(table->data, newval, newlen))
2566 return -EFAULT;
2568 return 1;
2571 /* The generic string strategy routine: */
2572 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2573 void __user *oldval, size_t __user *oldlenp,
2574 void __user *newval, size_t newlen)
2576 if (!table->data || !table->maxlen)
2577 return -ENOTDIR;
2579 if (oldval && oldlenp) {
2580 size_t bufsize;
2581 if (get_user(bufsize, oldlenp))
2582 return -EFAULT;
2583 if (bufsize) {
2584 size_t len = strlen(table->data), copied;
2586 /* This shouldn't trigger for a well-formed sysctl */
2587 if (len > table->maxlen)
2588 len = table->maxlen;
2590 /* Copy up to a max of bufsize-1 bytes of the string */
2591 copied = (len >= bufsize) ? bufsize - 1 : len;
2593 if (copy_to_user(oldval, table->data, copied) ||
2594 put_user(0, (char __user *)(oldval + copied)))
2595 return -EFAULT;
2596 if (put_user(len, oldlenp))
2597 return -EFAULT;
2600 if (newval && newlen) {
2601 size_t len = newlen;
2602 if (len > table->maxlen)
2603 len = table->maxlen;
2604 if(copy_from_user(table->data, newval, len))
2605 return -EFAULT;
2606 if (len == table->maxlen)
2607 len--;
2608 ((char *) table->data)[len] = 0;
2610 return 1;
2614 * This function makes sure that all of the integers in the vector
2615 * are between the minimum and maximum values given in the arrays
2616 * table->extra1 and table->extra2, respectively.
2618 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2619 void __user *oldval, size_t __user *oldlenp,
2620 void __user *newval, size_t newlen)
2623 if (newval && newlen) {
2624 int __user *vec = (int __user *) newval;
2625 int *min = (int *) table->extra1;
2626 int *max = (int *) table->extra2;
2627 size_t length;
2628 int i;
2630 if (newlen % sizeof(int) != 0)
2631 return -EINVAL;
2633 if (!table->extra1 && !table->extra2)
2634 return 0;
2636 if (newlen > table->maxlen)
2637 newlen = table->maxlen;
2638 length = newlen / sizeof(int);
2640 for (i = 0; i < length; i++) {
2641 int value;
2642 if (get_user(value, vec + i))
2643 return -EFAULT;
2644 if (min && value < min[i])
2645 return -EINVAL;
2646 if (max && value > max[i])
2647 return -EINVAL;
2650 return 0;
2653 /* Strategy function to convert jiffies to seconds */
2654 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2655 void __user *oldval, size_t __user *oldlenp,
2656 void __user *newval, size_t newlen)
2658 if (oldval && oldlenp) {
2659 size_t olen;
2661 if (get_user(olen, oldlenp))
2662 return -EFAULT;
2663 if (olen) {
2664 int val;
2666 if (olen < sizeof(int))
2667 return -EINVAL;
2669 val = *(int *)(table->data) / HZ;
2670 if (put_user(val, (int __user *)oldval))
2671 return -EFAULT;
2672 if (put_user(sizeof(int), oldlenp))
2673 return -EFAULT;
2676 if (newval && newlen) {
2677 int new;
2678 if (newlen != sizeof(int))
2679 return -EINVAL;
2680 if (get_user(new, (int __user *)newval))
2681 return -EFAULT;
2682 *(int *)(table->data) = new*HZ;
2684 return 1;
2687 /* Strategy function to convert jiffies to seconds */
2688 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2689 void __user *oldval, size_t __user *oldlenp,
2690 void __user *newval, size_t newlen)
2692 if (oldval && oldlenp) {
2693 size_t olen;
2695 if (get_user(olen, oldlenp))
2696 return -EFAULT;
2697 if (olen) {
2698 int val;
2700 if (olen < sizeof(int))
2701 return -EINVAL;
2703 val = jiffies_to_msecs(*(int *)(table->data));
2704 if (put_user(val, (int __user *)oldval))
2705 return -EFAULT;
2706 if (put_user(sizeof(int), oldlenp))
2707 return -EFAULT;
2710 if (newval && newlen) {
2711 int new;
2712 if (newlen != sizeof(int))
2713 return -EINVAL;
2714 if (get_user(new, (int __user *)newval))
2715 return -EFAULT;
2716 *(int *)(table->data) = msecs_to_jiffies(new);
2718 return 1;
2723 #else /* CONFIG_SYSCTL_SYSCALL */
2726 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2728 struct __sysctl_args tmp;
2729 int error;
2731 if (copy_from_user(&tmp, args, sizeof(tmp)))
2732 return -EFAULT;
2734 error = deprecated_sysctl_warning(&tmp);
2736 /* If no error reading the parameters then just -ENOSYS ... */
2737 if (!error)
2738 error = -ENOSYS;
2740 return error;
2743 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2744 void __user *oldval, size_t __user *oldlenp,
2745 void __user *newval, size_t newlen)
2747 return -ENOSYS;
2750 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2751 void __user *oldval, size_t __user *oldlenp,
2752 void __user *newval, size_t newlen)
2754 return -ENOSYS;
2757 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2758 void __user *oldval, size_t __user *oldlenp,
2759 void __user *newval, size_t newlen)
2761 return -ENOSYS;
2764 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2765 void __user *oldval, size_t __user *oldlenp,
2766 void __user *newval, size_t newlen)
2768 return -ENOSYS;
2771 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2772 void __user *oldval, size_t __user *oldlenp,
2773 void __user *newval, size_t newlen)
2775 return -ENOSYS;
2778 #endif /* CONFIG_SYSCTL_SYSCALL */
2780 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2782 static int msg_count;
2783 int name[CTL_MAXNAME];
2784 int i;
2786 /* Check args->nlen. */
2787 if (args->nlen < 0 || args->nlen > CTL_MAXNAME)
2788 return -ENOTDIR;
2790 /* Read in the sysctl name for better debug message logging */
2791 for (i = 0; i < args->nlen; i++)
2792 if (get_user(name[i], args->name + i))
2793 return -EFAULT;
2795 /* Ignore accesses to kernel.version */
2796 if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2797 return 0;
2799 if (msg_count < 5) {
2800 msg_count++;
2801 printk(KERN_INFO
2802 "warning: process `%s' used the deprecated sysctl "
2803 "system call with ", current->comm);
2804 for (i = 0; i < args->nlen; i++)
2805 printk("%d.", name[i]);
2806 printk("\n");
2808 return 0;
2812 * No sense putting this after each symbol definition, twice,
2813 * exception granted :-)
2815 EXPORT_SYMBOL(proc_dointvec);
2816 EXPORT_SYMBOL(proc_dointvec_jiffies);
2817 EXPORT_SYMBOL(proc_dointvec_minmax);
2818 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2819 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2820 EXPORT_SYMBOL(proc_dostring);
2821 EXPORT_SYMBOL(proc_doulongvec_minmax);
2822 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2823 EXPORT_SYMBOL(register_sysctl_table);
2824 EXPORT_SYMBOL(register_sysctl_paths);
2825 EXPORT_SYMBOL(sysctl_intvec);
2826 EXPORT_SYMBOL(sysctl_jiffies);
2827 EXPORT_SYMBOL(sysctl_ms_jiffies);
2828 EXPORT_SYMBOL(sysctl_string);
2829 EXPORT_SYMBOL(sysctl_data);
2830 EXPORT_SYMBOL(unregister_sysctl_table);