sysctl: x86_64 remove unnecessary binary paths
[linux-2.6/kmemtrace.git] / kernel / sysctl.c
blob8e8f3f4cf14b699126bc7174039c6d746d31f3c1
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/capability.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/security.h>
41 #include <linux/initrd.h>
42 #include <linux/times.h>
43 #include <linux/limits.h>
44 #include <linux/dcache.h>
45 #include <linux/syscalls.h>
46 #include <linux/nfs_fs.h>
47 #include <linux/acpi.h>
48 #include <linux/reboot.h>
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
53 #ifdef CONFIG_X86
54 #include <asm/nmi.h>
55 #include <asm/stacktrace.h>
56 #endif
58 #if defined(CONFIG_SYSCTL)
60 /* External variables not in a header file. */
61 extern int C_A_D;
62 extern int print_fatal_signals;
63 extern int sysctl_overcommit_memory;
64 extern int sysctl_overcommit_ratio;
65 extern int sysctl_panic_on_oom;
66 extern int sysctl_oom_kill_allocating_task;
67 extern int max_threads;
68 extern int core_uses_pid;
69 extern int suid_dumpable;
70 extern char core_pattern[];
71 extern int pid_max;
72 extern int min_free_kbytes;
73 extern int printk_ratelimit_jiffies;
74 extern int printk_ratelimit_burst;
75 extern int pid_max_min, pid_max_max;
76 extern int sysctl_drop_caches;
77 extern int percpu_pagelist_fraction;
78 extern int compat_log;
79 extern int maps_protect;
80 extern int sysctl_stat_interval;
81 extern int audit_argv_kb;
83 /* Constants used for minimum and maximum */
84 #ifdef CONFIG_DETECT_SOFTLOCKUP
85 static int one = 1;
86 static int sixty = 60;
87 #endif
89 #ifdef CONFIG_MMU
90 static int two = 2;
91 #endif
93 static int zero;
94 static int one_hundred = 100;
96 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
97 static int maxolduid = 65535;
98 static int minolduid;
99 static int min_percpu_pagelist_fract = 8;
101 static int ngroups_max = NGROUPS_MAX;
103 #ifdef CONFIG_KMOD
104 extern char modprobe_path[];
105 #endif
106 #ifdef CONFIG_CHR_DEV_SG
107 extern int sg_big_buff;
108 #endif
110 #ifdef __sparc__
111 extern char reboot_command [];
112 extern int stop_a_enabled;
113 extern int scons_pwroff;
114 #endif
116 #ifdef __hppa__
117 extern int pwrsw_enabled;
118 extern int unaligned_enabled;
119 #endif
121 #ifdef CONFIG_S390
122 #ifdef CONFIG_MATHEMU
123 extern int sysctl_ieee_emulation_warnings;
124 #endif
125 extern int sysctl_userprocess_debug;
126 extern int spin_retry;
127 #endif
129 extern int sysctl_hz_timer;
131 #ifdef CONFIG_BSD_PROCESS_ACCT
132 extern int acct_parm[];
133 #endif
135 #ifdef CONFIG_IA64
136 extern int no_unaligned_warning;
137 #endif
139 #ifdef CONFIG_RT_MUTEXES
140 extern int max_lock_depth;
141 #endif
143 #ifdef CONFIG_SYSCTL_SYSCALL
144 static int parse_table(int __user *, int, void __user *, size_t __user *,
145 void __user *, size_t, struct ctl_table *);
146 #endif
149 #ifdef CONFIG_PROC_SYSCTL
150 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
151 void __user *buffer, size_t *lenp, loff_t *ppos);
152 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
153 void __user *buffer, size_t *lenp, loff_t *ppos);
154 #endif
156 static struct ctl_table root_table[];
157 static struct ctl_table_header root_table_header =
158 { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
160 static struct ctl_table kern_table[];
161 static struct ctl_table vm_table[];
162 static struct ctl_table fs_table[];
163 static struct ctl_table debug_table[];
164 static struct ctl_table dev_table[];
165 extern struct ctl_table random_table[];
166 #ifdef CONFIG_UNIX98_PTYS
167 extern struct ctl_table pty_table[];
168 #endif
169 #ifdef CONFIG_INOTIFY_USER
170 extern struct ctl_table inotify_table[];
171 #endif
173 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
174 int sysctl_legacy_va_layout;
175 #endif
177 extern int prove_locking;
178 extern int lock_stat;
180 /* The default sysctl tables: */
182 static struct ctl_table root_table[] = {
184 .ctl_name = CTL_KERN,
185 .procname = "kernel",
186 .mode = 0555,
187 .child = kern_table,
190 .ctl_name = CTL_VM,
191 .procname = "vm",
192 .mode = 0555,
193 .child = vm_table,
195 #ifdef CONFIG_NET
197 .ctl_name = CTL_NET,
198 .procname = "net",
199 .mode = 0555,
200 .child = net_table,
202 #endif
204 .ctl_name = CTL_FS,
205 .procname = "fs",
206 .mode = 0555,
207 .child = fs_table,
210 .ctl_name = CTL_DEBUG,
211 .procname = "debug",
212 .mode = 0555,
213 .child = debug_table,
216 .ctl_name = CTL_DEV,
217 .procname = "dev",
218 .mode = 0555,
219 .child = dev_table,
222 * NOTE: do not add new entries to this table unless you have read
223 * Documentation/sysctl/ctl_unnumbered.txt
225 { .ctl_name = 0 }
228 #ifdef CONFIG_SCHED_DEBUG
229 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
230 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
231 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
232 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
233 #endif
235 static struct ctl_table kern_table[] = {
236 #ifdef CONFIG_SCHED_DEBUG
238 .ctl_name = CTL_UNNUMBERED,
239 .procname = "sched_nr_latency",
240 .data = &sysctl_sched_nr_latency,
241 .maxlen = sizeof(unsigned int),
242 .mode = 0644,
243 .proc_handler = &proc_dointvec,
246 .ctl_name = CTL_UNNUMBERED,
247 .procname = "sched_latency_ns",
248 .data = &sysctl_sched_latency,
249 .maxlen = sizeof(unsigned int),
250 .mode = 0644,
251 .proc_handler = &proc_dointvec_minmax,
252 .strategy = &sysctl_intvec,
253 .extra1 = &min_sched_granularity_ns,
254 .extra2 = &max_sched_granularity_ns,
257 .ctl_name = CTL_UNNUMBERED,
258 .procname = "sched_wakeup_granularity_ns",
259 .data = &sysctl_sched_wakeup_granularity,
260 .maxlen = sizeof(unsigned int),
261 .mode = 0644,
262 .proc_handler = &proc_dointvec_minmax,
263 .strategy = &sysctl_intvec,
264 .extra1 = &min_wakeup_granularity_ns,
265 .extra2 = &max_wakeup_granularity_ns,
268 .ctl_name = CTL_UNNUMBERED,
269 .procname = "sched_batch_wakeup_granularity_ns",
270 .data = &sysctl_sched_batch_wakeup_granularity,
271 .maxlen = sizeof(unsigned int),
272 .mode = 0644,
273 .proc_handler = &proc_dointvec_minmax,
274 .strategy = &sysctl_intvec,
275 .extra1 = &min_wakeup_granularity_ns,
276 .extra2 = &max_wakeup_granularity_ns,
279 .ctl_name = CTL_UNNUMBERED,
280 .procname = "sched_child_runs_first",
281 .data = &sysctl_sched_child_runs_first,
282 .maxlen = sizeof(unsigned int),
283 .mode = 0644,
284 .proc_handler = &proc_dointvec,
287 .ctl_name = CTL_UNNUMBERED,
288 .procname = "sched_features",
289 .data = &sysctl_sched_features,
290 .maxlen = sizeof(unsigned int),
291 .mode = 0644,
292 .proc_handler = &proc_dointvec,
295 .ctl_name = CTL_UNNUMBERED,
296 .procname = "sched_migration_cost",
297 .data = &sysctl_sched_migration_cost,
298 .maxlen = sizeof(unsigned int),
299 .mode = 0644,
300 .proc_handler = &proc_dointvec,
302 #endif
304 .ctl_name = CTL_UNNUMBERED,
305 .procname = "sched_compat_yield",
306 .data = &sysctl_sched_compat_yield,
307 .maxlen = sizeof(unsigned int),
308 .mode = 0644,
309 .proc_handler = &proc_dointvec,
311 #ifdef CONFIG_PROVE_LOCKING
313 .ctl_name = CTL_UNNUMBERED,
314 .procname = "prove_locking",
315 .data = &prove_locking,
316 .maxlen = sizeof(int),
317 .mode = 0644,
318 .proc_handler = &proc_dointvec,
320 #endif
321 #ifdef CONFIG_LOCK_STAT
323 .ctl_name = CTL_UNNUMBERED,
324 .procname = "lock_stat",
325 .data = &lock_stat,
326 .maxlen = sizeof(int),
327 .mode = 0644,
328 .proc_handler = &proc_dointvec,
330 #endif
332 .ctl_name = KERN_PANIC,
333 .procname = "panic",
334 .data = &panic_timeout,
335 .maxlen = sizeof(int),
336 .mode = 0644,
337 .proc_handler = &proc_dointvec,
340 .ctl_name = KERN_CORE_USES_PID,
341 .procname = "core_uses_pid",
342 .data = &core_uses_pid,
343 .maxlen = sizeof(int),
344 .mode = 0644,
345 .proc_handler = &proc_dointvec,
347 #ifdef CONFIG_AUDITSYSCALL
349 .ctl_name = CTL_UNNUMBERED,
350 .procname = "audit_argv_kb",
351 .data = &audit_argv_kb,
352 .maxlen = sizeof(int),
353 .mode = 0644,
354 .proc_handler = &proc_dointvec,
356 #endif
358 .ctl_name = KERN_CORE_PATTERN,
359 .procname = "core_pattern",
360 .data = core_pattern,
361 .maxlen = CORENAME_MAX_SIZE,
362 .mode = 0644,
363 .proc_handler = &proc_dostring,
364 .strategy = &sysctl_string,
366 #ifdef CONFIG_PROC_SYSCTL
368 .procname = "tainted",
369 .data = &tainted,
370 .maxlen = sizeof(int),
371 .mode = 0644,
372 .proc_handler = &proc_dointvec_taint,
374 #endif
376 .procname = "cap-bound",
377 .data = &cap_bset,
378 .maxlen = sizeof(kernel_cap_t),
379 .mode = 0600,
380 .proc_handler = &proc_dointvec_bset,
382 #ifdef CONFIG_BLK_DEV_INITRD
384 .ctl_name = KERN_REALROOTDEV,
385 .procname = "real-root-dev",
386 .data = &real_root_dev,
387 .maxlen = sizeof(int),
388 .mode = 0644,
389 .proc_handler = &proc_dointvec,
391 #endif
393 .ctl_name = CTL_UNNUMBERED,
394 .procname = "print-fatal-signals",
395 .data = &print_fatal_signals,
396 .maxlen = sizeof(int),
397 .mode = 0644,
398 .proc_handler = &proc_dointvec,
400 #ifdef __sparc__
402 .ctl_name = KERN_SPARC_REBOOT,
403 .procname = "reboot-cmd",
404 .data = reboot_command,
405 .maxlen = 256,
406 .mode = 0644,
407 .proc_handler = &proc_dostring,
408 .strategy = &sysctl_string,
411 .ctl_name = KERN_SPARC_STOP_A,
412 .procname = "stop-a",
413 .data = &stop_a_enabled,
414 .maxlen = sizeof (int),
415 .mode = 0644,
416 .proc_handler = &proc_dointvec,
419 .ctl_name = KERN_SPARC_SCONS_PWROFF,
420 .procname = "scons-poweroff",
421 .data = &scons_pwroff,
422 .maxlen = sizeof (int),
423 .mode = 0644,
424 .proc_handler = &proc_dointvec,
426 #endif
427 #ifdef __hppa__
429 .ctl_name = KERN_HPPA_PWRSW,
430 .procname = "soft-power",
431 .data = &pwrsw_enabled,
432 .maxlen = sizeof (int),
433 .mode = 0644,
434 .proc_handler = &proc_dointvec,
437 .ctl_name = KERN_HPPA_UNALIGNED,
438 .procname = "unaligned-trap",
439 .data = &unaligned_enabled,
440 .maxlen = sizeof (int),
441 .mode = 0644,
442 .proc_handler = &proc_dointvec,
444 #endif
446 .ctl_name = KERN_CTLALTDEL,
447 .procname = "ctrl-alt-del",
448 .data = &C_A_D,
449 .maxlen = sizeof(int),
450 .mode = 0644,
451 .proc_handler = &proc_dointvec,
454 .ctl_name = KERN_PRINTK,
455 .procname = "printk",
456 .data = &console_loglevel,
457 .maxlen = 4*sizeof(int),
458 .mode = 0644,
459 .proc_handler = &proc_dointvec,
461 #ifdef CONFIG_KMOD
463 .ctl_name = KERN_MODPROBE,
464 .procname = "modprobe",
465 .data = &modprobe_path,
466 .maxlen = KMOD_PATH_LEN,
467 .mode = 0644,
468 .proc_handler = &proc_dostring,
469 .strategy = &sysctl_string,
471 #endif
472 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
474 .ctl_name = KERN_HOTPLUG,
475 .procname = "hotplug",
476 .data = &uevent_helper,
477 .maxlen = UEVENT_HELPER_PATH_LEN,
478 .mode = 0644,
479 .proc_handler = &proc_dostring,
480 .strategy = &sysctl_string,
482 #endif
483 #ifdef CONFIG_CHR_DEV_SG
485 .ctl_name = KERN_SG_BIG_BUFF,
486 .procname = "sg-big-buff",
487 .data = &sg_big_buff,
488 .maxlen = sizeof (int),
489 .mode = 0444,
490 .proc_handler = &proc_dointvec,
492 #endif
493 #ifdef CONFIG_BSD_PROCESS_ACCT
495 .ctl_name = KERN_ACCT,
496 .procname = "acct",
497 .data = &acct_parm,
498 .maxlen = 3*sizeof(int),
499 .mode = 0644,
500 .proc_handler = &proc_dointvec,
502 #endif
503 #ifdef CONFIG_MAGIC_SYSRQ
505 .ctl_name = KERN_SYSRQ,
506 .procname = "sysrq",
507 .data = &__sysrq_enabled,
508 .maxlen = sizeof (int),
509 .mode = 0644,
510 .proc_handler = &proc_dointvec,
512 #endif
513 #ifdef CONFIG_PROC_SYSCTL
515 .ctl_name = KERN_CADPID,
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,
537 #ifdef CONFIG_UNIX98_PTYS
539 .ctl_name = KERN_PTY,
540 .procname = "pty",
541 .mode = 0555,
542 .child = pty_table,
544 #endif
546 .ctl_name = KERN_OVERFLOWUID,
547 .procname = "overflowuid",
548 .data = &overflowuid,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec_minmax,
552 .strategy = &sysctl_intvec,
553 .extra1 = &minolduid,
554 .extra2 = &maxolduid,
557 .ctl_name = KERN_OVERFLOWGID,
558 .procname = "overflowgid",
559 .data = &overflowgid,
560 .maxlen = sizeof(int),
561 .mode = 0644,
562 .proc_handler = &proc_dointvec_minmax,
563 .strategy = &sysctl_intvec,
564 .extra1 = &minolduid,
565 .extra2 = &maxolduid,
567 #ifdef CONFIG_S390
568 #ifdef CONFIG_MATHEMU
570 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
571 .procname = "ieee_emulation_warnings",
572 .data = &sysctl_ieee_emulation_warnings,
573 .maxlen = sizeof(int),
574 .mode = 0644,
575 .proc_handler = &proc_dointvec,
577 #endif
578 #ifdef CONFIG_NO_IDLE_HZ
580 .ctl_name = KERN_HZ_TIMER,
581 .procname = "hz_timer",
582 .data = &sysctl_hz_timer,
583 .maxlen = sizeof(int),
584 .mode = 0644,
585 .proc_handler = &proc_dointvec,
587 #endif
589 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
590 .procname = "userprocess_debug",
591 .data = &sysctl_userprocess_debug,
592 .maxlen = sizeof(int),
593 .mode = 0644,
594 .proc_handler = &proc_dointvec,
596 #endif
598 .ctl_name = KERN_PIDMAX,
599 .procname = "pid_max",
600 .data = &pid_max,
601 .maxlen = sizeof (int),
602 .mode = 0644,
603 .proc_handler = &proc_dointvec_minmax,
604 .strategy = sysctl_intvec,
605 .extra1 = &pid_max_min,
606 .extra2 = &pid_max_max,
609 .ctl_name = KERN_PANIC_ON_OOPS,
610 .procname = "panic_on_oops",
611 .data = &panic_on_oops,
612 .maxlen = sizeof(int),
613 .mode = 0644,
614 .proc_handler = &proc_dointvec,
617 .ctl_name = KERN_PRINTK_RATELIMIT,
618 .procname = "printk_ratelimit",
619 .data = &printk_ratelimit_jiffies,
620 .maxlen = sizeof(int),
621 .mode = 0644,
622 .proc_handler = &proc_dointvec_jiffies,
623 .strategy = &sysctl_jiffies,
626 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
627 .procname = "printk_ratelimit_burst",
628 .data = &printk_ratelimit_burst,
629 .maxlen = sizeof(int),
630 .mode = 0644,
631 .proc_handler = &proc_dointvec,
634 .ctl_name = KERN_NGROUPS_MAX,
635 .procname = "ngroups_max",
636 .data = &ngroups_max,
637 .maxlen = sizeof (int),
638 .mode = 0444,
639 .proc_handler = &proc_dointvec,
641 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
643 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
644 .procname = "unknown_nmi_panic",
645 .data = &unknown_nmi_panic,
646 .maxlen = sizeof (int),
647 .mode = 0644,
648 .proc_handler = &proc_dointvec,
651 .procname = "nmi_watchdog",
652 .data = &nmi_watchdog_enabled,
653 .maxlen = sizeof (int),
654 .mode = 0644,
655 .proc_handler = &proc_nmi_enabled,
657 #endif
658 #if defined(CONFIG_X86)
660 .ctl_name = KERN_PANIC_ON_NMI,
661 .procname = "panic_on_unrecovered_nmi",
662 .data = &panic_on_unrecovered_nmi,
663 .maxlen = sizeof(int),
664 .mode = 0644,
665 .proc_handler = &proc_dointvec,
668 .ctl_name = KERN_BOOTLOADER_TYPE,
669 .procname = "bootloader_type",
670 .data = &bootloader_type,
671 .maxlen = sizeof (int),
672 .mode = 0444,
673 .proc_handler = &proc_dointvec,
676 .ctl_name = CTL_UNNUMBERED,
677 .procname = "kstack_depth_to_print",
678 .data = &kstack_depth_to_print,
679 .maxlen = sizeof(int),
680 .mode = 0644,
681 .proc_handler = &proc_dointvec,
683 #endif
684 #if defined(CONFIG_MMU)
686 .ctl_name = KERN_RANDOMIZE,
687 .procname = "randomize_va_space",
688 .data = &randomize_va_space,
689 .maxlen = sizeof(int),
690 .mode = 0644,
691 .proc_handler = &proc_dointvec,
693 #endif
694 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
696 .ctl_name = KERN_SPIN_RETRY,
697 .procname = "spin_retry",
698 .data = &spin_retry,
699 .maxlen = sizeof (int),
700 .mode = 0644,
701 .proc_handler = &proc_dointvec,
703 #endif
704 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
706 .ctl_name = KERN_ACPI_VIDEO_FLAGS,
707 .procname = "acpi_video_flags",
708 .data = &acpi_realmode_flags,
709 .maxlen = sizeof (unsigned long),
710 .mode = 0644,
711 .proc_handler = &proc_doulongvec_minmax,
713 #endif
714 #ifdef CONFIG_IA64
716 .ctl_name = KERN_IA64_UNALIGNED,
717 .procname = "ignore-unaligned-usertrap",
718 .data = &no_unaligned_warning,
719 .maxlen = sizeof (int),
720 .mode = 0644,
721 .proc_handler = &proc_dointvec,
723 #endif
724 #ifdef CONFIG_DETECT_SOFTLOCKUP
726 .ctl_name = CTL_UNNUMBERED,
727 .procname = "softlockup_thresh",
728 .data = &softlockup_thresh,
729 .maxlen = sizeof(int),
730 .mode = 0644,
731 .proc_handler = &proc_dointvec_minmax,
732 .strategy = &sysctl_intvec,
733 .extra1 = &one,
734 .extra2 = &sixty,
736 #endif
737 #ifdef CONFIG_COMPAT
739 .ctl_name = KERN_COMPAT_LOG,
740 .procname = "compat-log",
741 .data = &compat_log,
742 .maxlen = sizeof (int),
743 .mode = 0644,
744 .proc_handler = &proc_dointvec,
746 #endif
747 #ifdef CONFIG_RT_MUTEXES
749 .ctl_name = KERN_MAX_LOCK_DEPTH,
750 .procname = "max_lock_depth",
751 .data = &max_lock_depth,
752 .maxlen = sizeof(int),
753 .mode = 0644,
754 .proc_handler = &proc_dointvec,
756 #endif
757 #ifdef CONFIG_PROC_FS
759 .ctl_name = CTL_UNNUMBERED,
760 .procname = "maps_protect",
761 .data = &maps_protect,
762 .maxlen = sizeof(int),
763 .mode = 0644,
764 .proc_handler = &proc_dointvec,
766 #endif
768 .ctl_name = CTL_UNNUMBERED,
769 .procname = "poweroff_cmd",
770 .data = &poweroff_cmd,
771 .maxlen = POWEROFF_CMD_PATH_LEN,
772 .mode = 0644,
773 .proc_handler = &proc_dostring,
774 .strategy = &sysctl_string,
777 * NOTE: do not add new entries to this table unless you have read
778 * Documentation/sysctl/ctl_unnumbered.txt
780 { .ctl_name = 0 }
783 static struct ctl_table vm_table[] = {
785 .ctl_name = VM_OVERCOMMIT_MEMORY,
786 .procname = "overcommit_memory",
787 .data = &sysctl_overcommit_memory,
788 .maxlen = sizeof(sysctl_overcommit_memory),
789 .mode = 0644,
790 .proc_handler = &proc_dointvec,
793 .ctl_name = VM_PANIC_ON_OOM,
794 .procname = "panic_on_oom",
795 .data = &sysctl_panic_on_oom,
796 .maxlen = sizeof(sysctl_panic_on_oom),
797 .mode = 0644,
798 .proc_handler = &proc_dointvec,
801 .ctl_name = CTL_UNNUMBERED,
802 .procname = "oom_kill_allocating_task",
803 .data = &sysctl_oom_kill_allocating_task,
804 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
805 .mode = 0644,
806 .proc_handler = &proc_dointvec,
809 .ctl_name = VM_OVERCOMMIT_RATIO,
810 .procname = "overcommit_ratio",
811 .data = &sysctl_overcommit_ratio,
812 .maxlen = sizeof(sysctl_overcommit_ratio),
813 .mode = 0644,
814 .proc_handler = &proc_dointvec,
817 .ctl_name = VM_PAGE_CLUSTER,
818 .procname = "page-cluster",
819 .data = &page_cluster,
820 .maxlen = sizeof(int),
821 .mode = 0644,
822 .proc_handler = &proc_dointvec,
825 .ctl_name = VM_DIRTY_BACKGROUND,
826 .procname = "dirty_background_ratio",
827 .data = &dirty_background_ratio,
828 .maxlen = sizeof(dirty_background_ratio),
829 .mode = 0644,
830 .proc_handler = &proc_dointvec_minmax,
831 .strategy = &sysctl_intvec,
832 .extra1 = &zero,
833 .extra2 = &one_hundred,
836 .ctl_name = VM_DIRTY_RATIO,
837 .procname = "dirty_ratio",
838 .data = &vm_dirty_ratio,
839 .maxlen = sizeof(vm_dirty_ratio),
840 .mode = 0644,
841 .proc_handler = &dirty_ratio_handler,
842 .strategy = &sysctl_intvec,
843 .extra1 = &zero,
844 .extra2 = &one_hundred,
847 .procname = "dirty_writeback_centisecs",
848 .data = &dirty_writeback_interval,
849 .maxlen = sizeof(dirty_writeback_interval),
850 .mode = 0644,
851 .proc_handler = &dirty_writeback_centisecs_handler,
854 .procname = "dirty_expire_centisecs",
855 .data = &dirty_expire_interval,
856 .maxlen = sizeof(dirty_expire_interval),
857 .mode = 0644,
858 .proc_handler = &proc_dointvec_userhz_jiffies,
861 .ctl_name = VM_NR_PDFLUSH_THREADS,
862 .procname = "nr_pdflush_threads",
863 .data = &nr_pdflush_threads,
864 .maxlen = sizeof nr_pdflush_threads,
865 .mode = 0444 /* read-only*/,
866 .proc_handler = &proc_dointvec,
869 .ctl_name = VM_SWAPPINESS,
870 .procname = "swappiness",
871 .data = &vm_swappiness,
872 .maxlen = sizeof(vm_swappiness),
873 .mode = 0644,
874 .proc_handler = &proc_dointvec_minmax,
875 .strategy = &sysctl_intvec,
876 .extra1 = &zero,
877 .extra2 = &one_hundred,
879 #ifdef CONFIG_HUGETLB_PAGE
881 .procname = "nr_hugepages",
882 .data = &max_huge_pages,
883 .maxlen = sizeof(unsigned long),
884 .mode = 0644,
885 .proc_handler = &hugetlb_sysctl_handler,
886 .extra1 = (void *)&hugetlb_zero,
887 .extra2 = (void *)&hugetlb_infinity,
890 .ctl_name = VM_HUGETLB_GROUP,
891 .procname = "hugetlb_shm_group",
892 .data = &sysctl_hugetlb_shm_group,
893 .maxlen = sizeof(gid_t),
894 .mode = 0644,
895 .proc_handler = &proc_dointvec,
898 .ctl_name = CTL_UNNUMBERED,
899 .procname = "hugepages_treat_as_movable",
900 .data = &hugepages_treat_as_movable,
901 .maxlen = sizeof(int),
902 .mode = 0644,
903 .proc_handler = &hugetlb_treat_movable_handler,
906 .ctl_name = CTL_UNNUMBERED,
907 .procname = "hugetlb_dynamic_pool",
908 .data = &hugetlb_dynamic_pool,
909 .maxlen = sizeof(hugetlb_dynamic_pool),
910 .mode = 0644,
911 .proc_handler = &proc_dointvec,
913 #endif
915 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
916 .procname = "lowmem_reserve_ratio",
917 .data = &sysctl_lowmem_reserve_ratio,
918 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
919 .mode = 0644,
920 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
921 .strategy = &sysctl_intvec,
924 .ctl_name = VM_DROP_PAGECACHE,
925 .procname = "drop_caches",
926 .data = &sysctl_drop_caches,
927 .maxlen = sizeof(int),
928 .mode = 0644,
929 .proc_handler = drop_caches_sysctl_handler,
930 .strategy = &sysctl_intvec,
933 .ctl_name = VM_MIN_FREE_KBYTES,
934 .procname = "min_free_kbytes",
935 .data = &min_free_kbytes,
936 .maxlen = sizeof(min_free_kbytes),
937 .mode = 0644,
938 .proc_handler = &min_free_kbytes_sysctl_handler,
939 .strategy = &sysctl_intvec,
940 .extra1 = &zero,
943 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
944 .procname = "percpu_pagelist_fraction",
945 .data = &percpu_pagelist_fraction,
946 .maxlen = sizeof(percpu_pagelist_fraction),
947 .mode = 0644,
948 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
949 .strategy = &sysctl_intvec,
950 .extra1 = &min_percpu_pagelist_fract,
952 #ifdef CONFIG_MMU
954 .ctl_name = VM_MAX_MAP_COUNT,
955 .procname = "max_map_count",
956 .data = &sysctl_max_map_count,
957 .maxlen = sizeof(sysctl_max_map_count),
958 .mode = 0644,
959 .proc_handler = &proc_dointvec
961 #endif
963 .ctl_name = VM_LAPTOP_MODE,
964 .procname = "laptop_mode",
965 .data = &laptop_mode,
966 .maxlen = sizeof(laptop_mode),
967 .mode = 0644,
968 .proc_handler = &proc_dointvec_jiffies,
969 .strategy = &sysctl_jiffies,
972 .ctl_name = VM_BLOCK_DUMP,
973 .procname = "block_dump",
974 .data = &block_dump,
975 .maxlen = sizeof(block_dump),
976 .mode = 0644,
977 .proc_handler = &proc_dointvec,
978 .strategy = &sysctl_intvec,
979 .extra1 = &zero,
982 .ctl_name = VM_VFS_CACHE_PRESSURE,
983 .procname = "vfs_cache_pressure",
984 .data = &sysctl_vfs_cache_pressure,
985 .maxlen = sizeof(sysctl_vfs_cache_pressure),
986 .mode = 0644,
987 .proc_handler = &proc_dointvec,
988 .strategy = &sysctl_intvec,
989 .extra1 = &zero,
991 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
993 .ctl_name = VM_LEGACY_VA_LAYOUT,
994 .procname = "legacy_va_layout",
995 .data = &sysctl_legacy_va_layout,
996 .maxlen = sizeof(sysctl_legacy_va_layout),
997 .mode = 0644,
998 .proc_handler = &proc_dointvec,
999 .strategy = &sysctl_intvec,
1000 .extra1 = &zero,
1002 #endif
1003 #ifdef CONFIG_NUMA
1005 .ctl_name = VM_ZONE_RECLAIM_MODE,
1006 .procname = "zone_reclaim_mode",
1007 .data = &zone_reclaim_mode,
1008 .maxlen = sizeof(zone_reclaim_mode),
1009 .mode = 0644,
1010 .proc_handler = &proc_dointvec,
1011 .strategy = &sysctl_intvec,
1012 .extra1 = &zero,
1015 .ctl_name = VM_MIN_UNMAPPED,
1016 .procname = "min_unmapped_ratio",
1017 .data = &sysctl_min_unmapped_ratio,
1018 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1019 .mode = 0644,
1020 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1021 .strategy = &sysctl_intvec,
1022 .extra1 = &zero,
1023 .extra2 = &one_hundred,
1026 .ctl_name = VM_MIN_SLAB,
1027 .procname = "min_slab_ratio",
1028 .data = &sysctl_min_slab_ratio,
1029 .maxlen = sizeof(sysctl_min_slab_ratio),
1030 .mode = 0644,
1031 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1032 .strategy = &sysctl_intvec,
1033 .extra1 = &zero,
1034 .extra2 = &one_hundred,
1036 #endif
1037 #ifdef CONFIG_SMP
1039 .ctl_name = CTL_UNNUMBERED,
1040 .procname = "stat_interval",
1041 .data = &sysctl_stat_interval,
1042 .maxlen = sizeof(sysctl_stat_interval),
1043 .mode = 0644,
1044 .proc_handler = &proc_dointvec_jiffies,
1045 .strategy = &sysctl_jiffies,
1047 #endif
1048 #ifdef CONFIG_SECURITY
1050 .ctl_name = CTL_UNNUMBERED,
1051 .procname = "mmap_min_addr",
1052 .data = &mmap_min_addr,
1053 .maxlen = sizeof(unsigned long),
1054 .mode = 0644,
1055 .proc_handler = &proc_doulongvec_minmax,
1057 #endif
1058 #ifdef CONFIG_NUMA
1060 .ctl_name = CTL_UNNUMBERED,
1061 .procname = "numa_zonelist_order",
1062 .data = &numa_zonelist_order,
1063 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1064 .mode = 0644,
1065 .proc_handler = &numa_zonelist_order_handler,
1066 .strategy = &sysctl_string,
1068 #endif
1069 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1070 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1072 .ctl_name = VM_VDSO_ENABLED,
1073 .procname = "vdso_enabled",
1074 .data = &vdso_enabled,
1075 .maxlen = sizeof(vdso_enabled),
1076 .mode = 0644,
1077 .proc_handler = &proc_dointvec,
1078 .strategy = &sysctl_intvec,
1079 .extra1 = &zero,
1081 #endif
1083 * NOTE: do not add new entries to this table unless you have read
1084 * Documentation/sysctl/ctl_unnumbered.txt
1086 { .ctl_name = 0 }
1089 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1090 static struct ctl_table binfmt_misc_table[] = {
1091 { .ctl_name = 0 }
1093 #endif
1095 static struct ctl_table fs_table[] = {
1097 .ctl_name = FS_NRINODE,
1098 .procname = "inode-nr",
1099 .data = &inodes_stat,
1100 .maxlen = 2*sizeof(int),
1101 .mode = 0444,
1102 .proc_handler = &proc_dointvec,
1105 .ctl_name = FS_STATINODE,
1106 .procname = "inode-state",
1107 .data = &inodes_stat,
1108 .maxlen = 7*sizeof(int),
1109 .mode = 0444,
1110 .proc_handler = &proc_dointvec,
1113 .procname = "file-nr",
1114 .data = &files_stat,
1115 .maxlen = 3*sizeof(int),
1116 .mode = 0444,
1117 .proc_handler = &proc_nr_files,
1120 .ctl_name = FS_MAXFILE,
1121 .procname = "file-max",
1122 .data = &files_stat.max_files,
1123 .maxlen = sizeof(int),
1124 .mode = 0644,
1125 .proc_handler = &proc_dointvec,
1128 .ctl_name = FS_DENTRY,
1129 .procname = "dentry-state",
1130 .data = &dentry_stat,
1131 .maxlen = 6*sizeof(int),
1132 .mode = 0444,
1133 .proc_handler = &proc_dointvec,
1136 .ctl_name = FS_OVERFLOWUID,
1137 .procname = "overflowuid",
1138 .data = &fs_overflowuid,
1139 .maxlen = sizeof(int),
1140 .mode = 0644,
1141 .proc_handler = &proc_dointvec_minmax,
1142 .strategy = &sysctl_intvec,
1143 .extra1 = &minolduid,
1144 .extra2 = &maxolduid,
1147 .ctl_name = FS_OVERFLOWGID,
1148 .procname = "overflowgid",
1149 .data = &fs_overflowgid,
1150 .maxlen = sizeof(int),
1151 .mode = 0644,
1152 .proc_handler = &proc_dointvec_minmax,
1153 .strategy = &sysctl_intvec,
1154 .extra1 = &minolduid,
1155 .extra2 = &maxolduid,
1158 .ctl_name = FS_LEASES,
1159 .procname = "leases-enable",
1160 .data = &leases_enable,
1161 .maxlen = sizeof(int),
1162 .mode = 0644,
1163 .proc_handler = &proc_dointvec,
1165 #ifdef CONFIG_DNOTIFY
1167 .ctl_name = FS_DIR_NOTIFY,
1168 .procname = "dir-notify-enable",
1169 .data = &dir_notify_enable,
1170 .maxlen = sizeof(int),
1171 .mode = 0644,
1172 .proc_handler = &proc_dointvec,
1174 #endif
1175 #ifdef CONFIG_MMU
1177 .ctl_name = FS_LEASE_TIME,
1178 .procname = "lease-break-time",
1179 .data = &lease_break_time,
1180 .maxlen = sizeof(int),
1181 .mode = 0644,
1182 .proc_handler = &proc_dointvec_minmax,
1183 .strategy = &sysctl_intvec,
1184 .extra1 = &zero,
1185 .extra2 = &two,
1188 .ctl_name = FS_AIO_NR,
1189 .procname = "aio-nr",
1190 .data = &aio_nr,
1191 .maxlen = sizeof(aio_nr),
1192 .mode = 0444,
1193 .proc_handler = &proc_doulongvec_minmax,
1196 .ctl_name = FS_AIO_MAX_NR,
1197 .procname = "aio-max-nr",
1198 .data = &aio_max_nr,
1199 .maxlen = sizeof(aio_max_nr),
1200 .mode = 0644,
1201 .proc_handler = &proc_doulongvec_minmax,
1203 #ifdef CONFIG_INOTIFY_USER
1205 .ctl_name = FS_INOTIFY,
1206 .procname = "inotify",
1207 .mode = 0555,
1208 .child = inotify_table,
1210 #endif
1211 #endif
1213 .ctl_name = KERN_SETUID_DUMPABLE,
1214 .procname = "suid_dumpable",
1215 .data = &suid_dumpable,
1216 .maxlen = sizeof(int),
1217 .mode = 0644,
1218 .proc_handler = &proc_dointvec,
1220 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1222 .ctl_name = CTL_UNNUMBERED,
1223 .procname = "binfmt_misc",
1224 .mode = 0555,
1225 .child = binfmt_misc_table,
1227 #endif
1229 * NOTE: do not add new entries to this table unless you have read
1230 * Documentation/sysctl/ctl_unnumbered.txt
1232 { .ctl_name = 0 }
1235 static struct ctl_table debug_table[] = {
1236 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1238 .ctl_name = CTL_UNNUMBERED,
1239 .procname = "exception-trace",
1240 .data = &show_unhandled_signals,
1241 .maxlen = sizeof(int),
1242 .mode = 0644,
1243 .proc_handler = proc_dointvec
1245 #endif
1246 { .ctl_name = 0 }
1249 static struct ctl_table dev_table[] = {
1250 { .ctl_name = 0 }
1253 static DEFINE_SPINLOCK(sysctl_lock);
1255 /* called under sysctl_lock */
1256 static int use_table(struct ctl_table_header *p)
1258 if (unlikely(p->unregistering))
1259 return 0;
1260 p->used++;
1261 return 1;
1264 /* called under sysctl_lock */
1265 static void unuse_table(struct ctl_table_header *p)
1267 if (!--p->used)
1268 if (unlikely(p->unregistering))
1269 complete(p->unregistering);
1272 /* called under sysctl_lock, will reacquire if has to wait */
1273 static void start_unregistering(struct ctl_table_header *p)
1276 * if p->used is 0, nobody will ever touch that entry again;
1277 * we'll eliminate all paths to it before dropping sysctl_lock
1279 if (unlikely(p->used)) {
1280 struct completion wait;
1281 init_completion(&wait);
1282 p->unregistering = &wait;
1283 spin_unlock(&sysctl_lock);
1284 wait_for_completion(&wait);
1285 spin_lock(&sysctl_lock);
1288 * do not remove from the list until nobody holds it; walking the
1289 * list in do_sysctl() relies on that.
1291 list_del_init(&p->ctl_entry);
1294 void sysctl_head_finish(struct ctl_table_header *head)
1296 if (!head)
1297 return;
1298 spin_lock(&sysctl_lock);
1299 unuse_table(head);
1300 spin_unlock(&sysctl_lock);
1303 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1305 struct ctl_table_header *head;
1306 struct list_head *tmp;
1307 spin_lock(&sysctl_lock);
1308 if (prev) {
1309 tmp = &prev->ctl_entry;
1310 unuse_table(prev);
1311 goto next;
1313 tmp = &root_table_header.ctl_entry;
1314 for (;;) {
1315 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1317 if (!use_table(head))
1318 goto next;
1319 spin_unlock(&sysctl_lock);
1320 return head;
1321 next:
1322 tmp = tmp->next;
1323 if (tmp == &root_table_header.ctl_entry)
1324 break;
1326 spin_unlock(&sysctl_lock);
1327 return NULL;
1330 #ifdef CONFIG_SYSCTL_SYSCALL
1331 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1332 void __user *newval, size_t newlen)
1334 struct ctl_table_header *head;
1335 int error = -ENOTDIR;
1337 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1338 return -ENOTDIR;
1339 if (oldval) {
1340 int old_len;
1341 if (!oldlenp || get_user(old_len, oldlenp))
1342 return -EFAULT;
1345 for (head = sysctl_head_next(NULL); head;
1346 head = sysctl_head_next(head)) {
1347 error = parse_table(name, nlen, oldval, oldlenp,
1348 newval, newlen, head->ctl_table);
1349 if (error != -ENOTDIR) {
1350 sysctl_head_finish(head);
1351 break;
1354 return error;
1357 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1359 struct __sysctl_args tmp;
1360 int error;
1362 if (copy_from_user(&tmp, args, sizeof(tmp)))
1363 return -EFAULT;
1365 lock_kernel();
1366 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1367 tmp.newval, tmp.newlen);
1368 unlock_kernel();
1369 return error;
1371 #endif /* CONFIG_SYSCTL_SYSCALL */
1374 * sysctl_perm does NOT grant the superuser all rights automatically, because
1375 * some sysctl variables are readonly even to root.
1378 static int test_perm(int mode, int op)
1380 if (!current->euid)
1381 mode >>= 6;
1382 else if (in_egroup_p(0))
1383 mode >>= 3;
1384 if ((mode & op & 0007) == op)
1385 return 0;
1386 return -EACCES;
1389 int sysctl_perm(struct ctl_table *table, int op)
1391 int error;
1392 error = security_sysctl(table, op);
1393 if (error)
1394 return error;
1395 return test_perm(table->mode, op);
1398 #ifdef CONFIG_SYSCTL_SYSCALL
1399 static int parse_table(int __user *name, int nlen,
1400 void __user *oldval, size_t __user *oldlenp,
1401 void __user *newval, size_t newlen,
1402 struct ctl_table *table)
1404 int n;
1405 repeat:
1406 if (!nlen)
1407 return -ENOTDIR;
1408 if (get_user(n, name))
1409 return -EFAULT;
1410 for ( ; table->ctl_name || table->procname; table++) {
1411 if (!table->ctl_name)
1412 continue;
1413 if (n == table->ctl_name) {
1414 int error;
1415 if (table->child) {
1416 if (sysctl_perm(table, 001))
1417 return -EPERM;
1418 name++;
1419 nlen--;
1420 table = table->child;
1421 goto repeat;
1423 error = do_sysctl_strategy(table, name, nlen,
1424 oldval, oldlenp,
1425 newval, newlen);
1426 return error;
1429 return -ENOTDIR;
1432 /* Perform the actual read/write of a sysctl table entry. */
1433 int do_sysctl_strategy (struct ctl_table *table,
1434 int __user *name, int nlen,
1435 void __user *oldval, size_t __user *oldlenp,
1436 void __user *newval, size_t newlen)
1438 int op = 0, rc;
1440 if (oldval)
1441 op |= 004;
1442 if (newval)
1443 op |= 002;
1444 if (sysctl_perm(table, op))
1445 return -EPERM;
1447 if (table->strategy) {
1448 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1449 newval, newlen);
1450 if (rc < 0)
1451 return rc;
1452 if (rc > 0)
1453 return 0;
1456 /* If there is no strategy routine, or if the strategy returns
1457 * zero, proceed with automatic r/w */
1458 if (table->data && table->maxlen) {
1459 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1460 newval, newlen);
1461 if (rc < 0)
1462 return rc;
1464 return 0;
1466 #endif /* CONFIG_SYSCTL_SYSCALL */
1468 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1470 for (; table->ctl_name || table->procname; table++) {
1471 table->parent = parent;
1472 if (table->child)
1473 sysctl_set_parent(table, table->child);
1477 static __init int sysctl_init(void)
1479 sysctl_set_parent(NULL, root_table);
1480 return 0;
1483 core_initcall(sysctl_init);
1486 * register_sysctl_table - register a sysctl hierarchy
1487 * @table: the top-level table structure
1489 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1490 * array. An entry with a ctl_name of 0 terminates the table.
1492 * The members of the &struct ctl_table structure are used as follows:
1494 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1495 * must be unique within that level of sysctl
1497 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1498 * enter a sysctl file
1500 * data - a pointer to data for use by proc_handler
1502 * maxlen - the maximum size in bytes of the data
1504 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1506 * child - a pointer to the child sysctl table if this entry is a directory, or
1507 * %NULL.
1509 * proc_handler - the text handler routine (described below)
1511 * strategy - the strategy routine (described below)
1513 * de - for internal use by the sysctl routines
1515 * extra1, extra2 - extra pointers usable by the proc handler routines
1517 * Leaf nodes in the sysctl tree will be represented by a single file
1518 * under /proc; non-leaf nodes will be represented by directories.
1520 * sysctl(2) can automatically manage read and write requests through
1521 * the sysctl table. The data and maxlen fields of the ctl_table
1522 * struct enable minimal validation of the values being written to be
1523 * performed, and the mode field allows minimal authentication.
1525 * More sophisticated management can be enabled by the provision of a
1526 * strategy routine with the table entry. This will be called before
1527 * any automatic read or write of the data is performed.
1529 * The strategy routine may return
1531 * < 0 - Error occurred (error is passed to user process)
1533 * 0 - OK - proceed with automatic read or write.
1535 * > 0 - OK - read or write has been done by the strategy routine, so
1536 * return immediately.
1538 * There must be a proc_handler routine for any terminal nodes
1539 * mirrored under /proc/sys (non-terminals are handled by a built-in
1540 * directory handler). Several default handlers are available to
1541 * cover common cases -
1543 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1544 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1545 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1547 * It is the handler's job to read the input buffer from user memory
1548 * and process it. The handler should return 0 on success.
1550 * This routine returns %NULL on a failure to register, and a pointer
1551 * to the table header on success.
1553 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1555 struct ctl_table_header *tmp;
1556 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1557 if (!tmp)
1558 return NULL;
1559 tmp->ctl_table = table;
1560 INIT_LIST_HEAD(&tmp->ctl_entry);
1561 tmp->used = 0;
1562 tmp->unregistering = NULL;
1563 sysctl_set_parent(NULL, table);
1564 spin_lock(&sysctl_lock);
1565 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1566 spin_unlock(&sysctl_lock);
1567 return tmp;
1571 * unregister_sysctl_table - unregister a sysctl table hierarchy
1572 * @header: the header returned from register_sysctl_table
1574 * Unregisters the sysctl table and all children. proc entries may not
1575 * actually be removed until they are no longer used by anyone.
1577 void unregister_sysctl_table(struct ctl_table_header * header)
1579 might_sleep();
1580 spin_lock(&sysctl_lock);
1581 start_unregistering(header);
1582 spin_unlock(&sysctl_lock);
1583 kfree(header);
1586 #else /* !CONFIG_SYSCTL */
1587 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1589 return NULL;
1592 void unregister_sysctl_table(struct ctl_table_header * table)
1596 #endif /* CONFIG_SYSCTL */
1599 * /proc/sys support
1602 #ifdef CONFIG_PROC_SYSCTL
1604 static int _proc_do_string(void* data, int maxlen, int write,
1605 struct file *filp, void __user *buffer,
1606 size_t *lenp, loff_t *ppos)
1608 size_t len;
1609 char __user *p;
1610 char c;
1612 if (!data || !maxlen || !*lenp) {
1613 *lenp = 0;
1614 return 0;
1617 if (write) {
1618 len = 0;
1619 p = buffer;
1620 while (len < *lenp) {
1621 if (get_user(c, p++))
1622 return -EFAULT;
1623 if (c == 0 || c == '\n')
1624 break;
1625 len++;
1627 if (len >= maxlen)
1628 len = maxlen-1;
1629 if(copy_from_user(data, buffer, len))
1630 return -EFAULT;
1631 ((char *) data)[len] = 0;
1632 *ppos += *lenp;
1633 } else {
1634 len = strlen(data);
1635 if (len > maxlen)
1636 len = maxlen;
1638 if (*ppos > len) {
1639 *lenp = 0;
1640 return 0;
1643 data += *ppos;
1644 len -= *ppos;
1646 if (len > *lenp)
1647 len = *lenp;
1648 if (len)
1649 if(copy_to_user(buffer, data, len))
1650 return -EFAULT;
1651 if (len < *lenp) {
1652 if(put_user('\n', ((char __user *) buffer) + len))
1653 return -EFAULT;
1654 len++;
1656 *lenp = len;
1657 *ppos += len;
1659 return 0;
1663 * proc_dostring - read a string sysctl
1664 * @table: the sysctl table
1665 * @write: %TRUE if this is a write to the sysctl file
1666 * @filp: the file structure
1667 * @buffer: the user buffer
1668 * @lenp: the size of the user buffer
1669 * @ppos: file position
1671 * Reads/writes a string from/to the user buffer. If the kernel
1672 * buffer provided is not large enough to hold the string, the
1673 * string is truncated. The copied string is %NULL-terminated.
1674 * If the string is being read by the user process, it is copied
1675 * and a newline '\n' is added. It is truncated if the buffer is
1676 * not large enough.
1678 * Returns 0 on success.
1680 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1681 void __user *buffer, size_t *lenp, loff_t *ppos)
1683 return _proc_do_string(table->data, table->maxlen, write, filp,
1684 buffer, lenp, ppos);
1688 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1689 int *valp,
1690 int write, void *data)
1692 if (write) {
1693 *valp = *negp ? -*lvalp : *lvalp;
1694 } else {
1695 int val = *valp;
1696 if (val < 0) {
1697 *negp = -1;
1698 *lvalp = (unsigned long)-val;
1699 } else {
1700 *negp = 0;
1701 *lvalp = (unsigned long)val;
1704 return 0;
1707 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1708 int write, struct file *filp, void __user *buffer,
1709 size_t *lenp, loff_t *ppos,
1710 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1711 int write, void *data),
1712 void *data)
1714 #define TMPBUFLEN 21
1715 int *i, vleft, first=1, neg, val;
1716 unsigned long lval;
1717 size_t left, len;
1719 char buf[TMPBUFLEN], *p;
1720 char __user *s = buffer;
1722 if (!tbl_data || !table->maxlen || !*lenp ||
1723 (*ppos && !write)) {
1724 *lenp = 0;
1725 return 0;
1728 i = (int *) tbl_data;
1729 vleft = table->maxlen / sizeof(*i);
1730 left = *lenp;
1732 if (!conv)
1733 conv = do_proc_dointvec_conv;
1735 for (; left && vleft--; i++, first=0) {
1736 if (write) {
1737 while (left) {
1738 char c;
1739 if (get_user(c, s))
1740 return -EFAULT;
1741 if (!isspace(c))
1742 break;
1743 left--;
1744 s++;
1746 if (!left)
1747 break;
1748 neg = 0;
1749 len = left;
1750 if (len > sizeof(buf) - 1)
1751 len = sizeof(buf) - 1;
1752 if (copy_from_user(buf, s, len))
1753 return -EFAULT;
1754 buf[len] = 0;
1755 p = buf;
1756 if (*p == '-' && left > 1) {
1757 neg = 1;
1758 p++;
1760 if (*p < '0' || *p > '9')
1761 break;
1763 lval = simple_strtoul(p, &p, 0);
1765 len = p-buf;
1766 if ((len < left) && *p && !isspace(*p))
1767 break;
1768 if (neg)
1769 val = -val;
1770 s += len;
1771 left -= len;
1773 if (conv(&neg, &lval, i, 1, data))
1774 break;
1775 } else {
1776 p = buf;
1777 if (!first)
1778 *p++ = '\t';
1780 if (conv(&neg, &lval, i, 0, data))
1781 break;
1783 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1784 len = strlen(buf);
1785 if (len > left)
1786 len = left;
1787 if(copy_to_user(s, buf, len))
1788 return -EFAULT;
1789 left -= len;
1790 s += len;
1794 if (!write && !first && left) {
1795 if(put_user('\n', s))
1796 return -EFAULT;
1797 left--, s++;
1799 if (write) {
1800 while (left) {
1801 char c;
1802 if (get_user(c, s++))
1803 return -EFAULT;
1804 if (!isspace(c))
1805 break;
1806 left--;
1809 if (write && first)
1810 return -EINVAL;
1811 *lenp -= left;
1812 *ppos += *lenp;
1813 return 0;
1814 #undef TMPBUFLEN
1817 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1818 void __user *buffer, size_t *lenp, loff_t *ppos,
1819 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1820 int write, void *data),
1821 void *data)
1823 return __do_proc_dointvec(table->data, table, write, filp,
1824 buffer, lenp, ppos, conv, data);
1828 * proc_dointvec - read a vector of integers
1829 * @table: the sysctl table
1830 * @write: %TRUE if this is a write to the sysctl file
1831 * @filp: the file structure
1832 * @buffer: the user buffer
1833 * @lenp: the size of the user buffer
1834 * @ppos: file position
1836 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1837 * values from/to the user buffer, treated as an ASCII string.
1839 * Returns 0 on success.
1841 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1842 void __user *buffer, size_t *lenp, loff_t *ppos)
1844 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1845 NULL,NULL);
1848 #define OP_SET 0
1849 #define OP_AND 1
1850 #define OP_OR 2
1852 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1853 int *valp,
1854 int write, void *data)
1856 int op = *(int *)data;
1857 if (write) {
1858 int val = *negp ? -*lvalp : *lvalp;
1859 switch(op) {
1860 case OP_SET: *valp = val; break;
1861 case OP_AND: *valp &= val; break;
1862 case OP_OR: *valp |= val; break;
1864 } else {
1865 int val = *valp;
1866 if (val < 0) {
1867 *negp = -1;
1868 *lvalp = (unsigned long)-val;
1869 } else {
1870 *negp = 0;
1871 *lvalp = (unsigned long)val;
1874 return 0;
1878 * init may raise the set.
1881 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1882 void __user *buffer, size_t *lenp, loff_t *ppos)
1884 int op;
1886 if (write && !capable(CAP_SYS_MODULE)) {
1887 return -EPERM;
1890 op = is_init(current) ? OP_SET : OP_AND;
1891 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1892 do_proc_dointvec_bset_conv,&op);
1896 * Taint values can only be increased
1898 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1899 void __user *buffer, size_t *lenp, loff_t *ppos)
1901 int op;
1903 if (write && !capable(CAP_SYS_ADMIN))
1904 return -EPERM;
1906 op = OP_OR;
1907 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1908 do_proc_dointvec_bset_conv,&op);
1911 struct do_proc_dointvec_minmax_conv_param {
1912 int *min;
1913 int *max;
1916 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1917 int *valp,
1918 int write, void *data)
1920 struct do_proc_dointvec_minmax_conv_param *param = data;
1921 if (write) {
1922 int val = *negp ? -*lvalp : *lvalp;
1923 if ((param->min && *param->min > val) ||
1924 (param->max && *param->max < val))
1925 return -EINVAL;
1926 *valp = val;
1927 } else {
1928 int val = *valp;
1929 if (val < 0) {
1930 *negp = -1;
1931 *lvalp = (unsigned long)-val;
1932 } else {
1933 *negp = 0;
1934 *lvalp = (unsigned long)val;
1937 return 0;
1941 * proc_dointvec_minmax - read a vector of integers with min/max values
1942 * @table: the sysctl table
1943 * @write: %TRUE if this is a write to the sysctl file
1944 * @filp: the file structure
1945 * @buffer: the user buffer
1946 * @lenp: the size of the user buffer
1947 * @ppos: file position
1949 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1950 * values from/to the user buffer, treated as an ASCII string.
1952 * This routine will ensure the values are within the range specified by
1953 * table->extra1 (min) and table->extra2 (max).
1955 * Returns 0 on success.
1957 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1958 void __user *buffer, size_t *lenp, loff_t *ppos)
1960 struct do_proc_dointvec_minmax_conv_param param = {
1961 .min = (int *) table->extra1,
1962 .max = (int *) table->extra2,
1964 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1965 do_proc_dointvec_minmax_conv, &param);
1968 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1969 struct file *filp,
1970 void __user *buffer,
1971 size_t *lenp, loff_t *ppos,
1972 unsigned long convmul,
1973 unsigned long convdiv)
1975 #define TMPBUFLEN 21
1976 unsigned long *i, *min, *max, val;
1977 int vleft, first=1, neg;
1978 size_t len, left;
1979 char buf[TMPBUFLEN], *p;
1980 char __user *s = buffer;
1982 if (!data || !table->maxlen || !*lenp ||
1983 (*ppos && !write)) {
1984 *lenp = 0;
1985 return 0;
1988 i = (unsigned long *) data;
1989 min = (unsigned long *) table->extra1;
1990 max = (unsigned long *) table->extra2;
1991 vleft = table->maxlen / sizeof(unsigned long);
1992 left = *lenp;
1994 for (; left && vleft--; i++, min++, max++, first=0) {
1995 if (write) {
1996 while (left) {
1997 char c;
1998 if (get_user(c, s))
1999 return -EFAULT;
2000 if (!isspace(c))
2001 break;
2002 left--;
2003 s++;
2005 if (!left)
2006 break;
2007 neg = 0;
2008 len = left;
2009 if (len > TMPBUFLEN-1)
2010 len = TMPBUFLEN-1;
2011 if (copy_from_user(buf, s, len))
2012 return -EFAULT;
2013 buf[len] = 0;
2014 p = buf;
2015 if (*p == '-' && left > 1) {
2016 neg = 1;
2017 p++;
2019 if (*p < '0' || *p > '9')
2020 break;
2021 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2022 len = p-buf;
2023 if ((len < left) && *p && !isspace(*p))
2024 break;
2025 if (neg)
2026 val = -val;
2027 s += len;
2028 left -= len;
2030 if(neg)
2031 continue;
2032 if ((min && val < *min) || (max && val > *max))
2033 continue;
2034 *i = val;
2035 } else {
2036 p = buf;
2037 if (!first)
2038 *p++ = '\t';
2039 sprintf(p, "%lu", convdiv * (*i) / convmul);
2040 len = strlen(buf);
2041 if (len > left)
2042 len = left;
2043 if(copy_to_user(s, buf, len))
2044 return -EFAULT;
2045 left -= len;
2046 s += len;
2050 if (!write && !first && left) {
2051 if(put_user('\n', s))
2052 return -EFAULT;
2053 left--, s++;
2055 if (write) {
2056 while (left) {
2057 char c;
2058 if (get_user(c, s++))
2059 return -EFAULT;
2060 if (!isspace(c))
2061 break;
2062 left--;
2065 if (write && first)
2066 return -EINVAL;
2067 *lenp -= left;
2068 *ppos += *lenp;
2069 return 0;
2070 #undef TMPBUFLEN
2073 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2074 struct file *filp,
2075 void __user *buffer,
2076 size_t *lenp, loff_t *ppos,
2077 unsigned long convmul,
2078 unsigned long convdiv)
2080 return __do_proc_doulongvec_minmax(table->data, table, write,
2081 filp, buffer, lenp, ppos, convmul, convdiv);
2085 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2086 * @table: the sysctl table
2087 * @write: %TRUE if this is a write to the sysctl file
2088 * @filp: the file structure
2089 * @buffer: the user buffer
2090 * @lenp: the size of the user buffer
2091 * @ppos: file position
2093 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2094 * values from/to the user buffer, treated as an ASCII string.
2096 * This routine will ensure the values are within the range specified by
2097 * table->extra1 (min) and table->extra2 (max).
2099 * Returns 0 on success.
2101 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2102 void __user *buffer, size_t *lenp, loff_t *ppos)
2104 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2108 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2109 * @table: the sysctl table
2110 * @write: %TRUE if this is a write to the sysctl file
2111 * @filp: the file structure
2112 * @buffer: the user buffer
2113 * @lenp: the size of the user buffer
2114 * @ppos: file position
2116 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2117 * values from/to the user buffer, treated as an ASCII string. The values
2118 * are treated as milliseconds, and converted to jiffies when they are stored.
2120 * This routine will ensure the values are within the range specified by
2121 * table->extra1 (min) and table->extra2 (max).
2123 * Returns 0 on success.
2125 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2126 struct file *filp,
2127 void __user *buffer,
2128 size_t *lenp, loff_t *ppos)
2130 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2131 lenp, ppos, HZ, 1000l);
2135 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2136 int *valp,
2137 int write, void *data)
2139 if (write) {
2140 if (*lvalp > LONG_MAX / HZ)
2141 return 1;
2142 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2143 } else {
2144 int val = *valp;
2145 unsigned long lval;
2146 if (val < 0) {
2147 *negp = -1;
2148 lval = (unsigned long)-val;
2149 } else {
2150 *negp = 0;
2151 lval = (unsigned long)val;
2153 *lvalp = lval / HZ;
2155 return 0;
2158 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2159 int *valp,
2160 int write, void *data)
2162 if (write) {
2163 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2164 return 1;
2165 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2166 } else {
2167 int val = *valp;
2168 unsigned long lval;
2169 if (val < 0) {
2170 *negp = -1;
2171 lval = (unsigned long)-val;
2172 } else {
2173 *negp = 0;
2174 lval = (unsigned long)val;
2176 *lvalp = jiffies_to_clock_t(lval);
2178 return 0;
2181 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2182 int *valp,
2183 int write, void *data)
2185 if (write) {
2186 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2187 } else {
2188 int val = *valp;
2189 unsigned long lval;
2190 if (val < 0) {
2191 *negp = -1;
2192 lval = (unsigned long)-val;
2193 } else {
2194 *negp = 0;
2195 lval = (unsigned long)val;
2197 *lvalp = jiffies_to_msecs(lval);
2199 return 0;
2203 * proc_dointvec_jiffies - read a vector of integers as seconds
2204 * @table: the sysctl table
2205 * @write: %TRUE if this is a write to the sysctl file
2206 * @filp: the file structure
2207 * @buffer: the user buffer
2208 * @lenp: the size of the user buffer
2209 * @ppos: file position
2211 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2212 * values from/to the user buffer, treated as an ASCII string.
2213 * The values read are assumed to be in seconds, and are converted into
2214 * jiffies.
2216 * Returns 0 on success.
2218 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2219 void __user *buffer, size_t *lenp, loff_t *ppos)
2221 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2222 do_proc_dointvec_jiffies_conv,NULL);
2226 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2227 * @table: the sysctl table
2228 * @write: %TRUE if this is a write to the sysctl file
2229 * @filp: the file structure
2230 * @buffer: the user buffer
2231 * @lenp: the size of the user buffer
2232 * @ppos: pointer to the file position
2234 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2235 * values from/to the user buffer, treated as an ASCII string.
2236 * The values read are assumed to be in 1/USER_HZ seconds, and
2237 * are converted into jiffies.
2239 * Returns 0 on success.
2241 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2242 void __user *buffer, size_t *lenp, loff_t *ppos)
2244 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2245 do_proc_dointvec_userhz_jiffies_conv,NULL);
2249 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2250 * @table: the sysctl table
2251 * @write: %TRUE if this is a write to the sysctl file
2252 * @filp: the file structure
2253 * @buffer: the user buffer
2254 * @lenp: the size of the user buffer
2255 * @ppos: file position
2256 * @ppos: the current position in the file
2258 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2259 * values from/to the user buffer, treated as an ASCII string.
2260 * The values read are assumed to be in 1/1000 seconds, and
2261 * are converted into jiffies.
2263 * Returns 0 on success.
2265 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2266 void __user *buffer, size_t *lenp, loff_t *ppos)
2268 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2269 do_proc_dointvec_ms_jiffies_conv, NULL);
2272 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2273 void __user *buffer, size_t *lenp, loff_t *ppos)
2275 struct pid *new_pid;
2276 pid_t tmp;
2277 int r;
2279 tmp = pid_nr(cad_pid);
2281 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2282 lenp, ppos, NULL, NULL);
2283 if (r || !write)
2284 return r;
2286 new_pid = find_get_pid(tmp);
2287 if (!new_pid)
2288 return -ESRCH;
2290 put_pid(xchg(&cad_pid, new_pid));
2291 return 0;
2294 #else /* CONFIG_PROC_FS */
2296 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2297 void __user *buffer, size_t *lenp, loff_t *ppos)
2299 return -ENOSYS;
2302 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2303 void __user *buffer, size_t *lenp, loff_t *ppos)
2305 return -ENOSYS;
2308 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2309 void __user *buffer, size_t *lenp, loff_t *ppos)
2311 return -ENOSYS;
2314 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2315 void __user *buffer, size_t *lenp, loff_t *ppos)
2317 return -ENOSYS;
2320 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2321 void __user *buffer, size_t *lenp, loff_t *ppos)
2323 return -ENOSYS;
2326 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2327 void __user *buffer, size_t *lenp, loff_t *ppos)
2329 return -ENOSYS;
2332 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2333 void __user *buffer, size_t *lenp, loff_t *ppos)
2335 return -ENOSYS;
2338 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2339 void __user *buffer, size_t *lenp, loff_t *ppos)
2341 return -ENOSYS;
2344 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2345 struct file *filp,
2346 void __user *buffer,
2347 size_t *lenp, loff_t *ppos)
2349 return -ENOSYS;
2353 #endif /* CONFIG_PROC_FS */
2356 #ifdef CONFIG_SYSCTL_SYSCALL
2358 * General sysctl support routines
2361 /* The generic sysctl data routine (used if no strategy routine supplied) */
2362 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2363 void __user *oldval, size_t __user *oldlenp,
2364 void __user *newval, size_t newlen)
2366 size_t len;
2368 /* Get out of I don't have a variable */
2369 if (!table->data || !table->maxlen)
2370 return -ENOTDIR;
2372 if (oldval && oldlenp) {
2373 if (get_user(len, oldlenp))
2374 return -EFAULT;
2375 if (len) {
2376 if (len > table->maxlen)
2377 len = table->maxlen;
2378 if (copy_to_user(oldval, table->data, len))
2379 return -EFAULT;
2380 if (put_user(len, oldlenp))
2381 return -EFAULT;
2385 if (newval && newlen) {
2386 if (newlen > table->maxlen)
2387 newlen = table->maxlen;
2389 if (copy_from_user(table->data, newval, newlen))
2390 return -EFAULT;
2392 return 1;
2395 /* The generic string strategy routine: */
2396 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2397 void __user *oldval, size_t __user *oldlenp,
2398 void __user *newval, size_t newlen)
2400 if (!table->data || !table->maxlen)
2401 return -ENOTDIR;
2403 if (oldval && oldlenp) {
2404 size_t bufsize;
2405 if (get_user(bufsize, oldlenp))
2406 return -EFAULT;
2407 if (bufsize) {
2408 size_t len = strlen(table->data), copied;
2410 /* This shouldn't trigger for a well-formed sysctl */
2411 if (len > table->maxlen)
2412 len = table->maxlen;
2414 /* Copy up to a max of bufsize-1 bytes of the string */
2415 copied = (len >= bufsize) ? bufsize - 1 : len;
2417 if (copy_to_user(oldval, table->data, copied) ||
2418 put_user(0, (char __user *)(oldval + copied)))
2419 return -EFAULT;
2420 if (put_user(len, oldlenp))
2421 return -EFAULT;
2424 if (newval && newlen) {
2425 size_t len = newlen;
2426 if (len > table->maxlen)
2427 len = table->maxlen;
2428 if(copy_from_user(table->data, newval, len))
2429 return -EFAULT;
2430 if (len == table->maxlen)
2431 len--;
2432 ((char *) table->data)[len] = 0;
2434 return 1;
2438 * This function makes sure that all of the integers in the vector
2439 * are between the minimum and maximum values given in the arrays
2440 * table->extra1 and table->extra2, respectively.
2442 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2443 void __user *oldval, size_t __user *oldlenp,
2444 void __user *newval, size_t newlen)
2447 if (newval && newlen) {
2448 int __user *vec = (int __user *) newval;
2449 int *min = (int *) table->extra1;
2450 int *max = (int *) table->extra2;
2451 size_t length;
2452 int i;
2454 if (newlen % sizeof(int) != 0)
2455 return -EINVAL;
2457 if (!table->extra1 && !table->extra2)
2458 return 0;
2460 if (newlen > table->maxlen)
2461 newlen = table->maxlen;
2462 length = newlen / sizeof(int);
2464 for (i = 0; i < length; i++) {
2465 int value;
2466 if (get_user(value, vec + i))
2467 return -EFAULT;
2468 if (min && value < min[i])
2469 return -EINVAL;
2470 if (max && value > max[i])
2471 return -EINVAL;
2474 return 0;
2477 /* Strategy function to convert jiffies to seconds */
2478 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2479 void __user *oldval, size_t __user *oldlenp,
2480 void __user *newval, size_t newlen)
2482 if (oldval && oldlenp) {
2483 size_t olen;
2485 if (get_user(olen, oldlenp))
2486 return -EFAULT;
2487 if (olen) {
2488 int val;
2490 if (olen < sizeof(int))
2491 return -EINVAL;
2493 val = *(int *)(table->data) / HZ;
2494 if (put_user(val, (int __user *)oldval))
2495 return -EFAULT;
2496 if (put_user(sizeof(int), oldlenp))
2497 return -EFAULT;
2500 if (newval && newlen) {
2501 int new;
2502 if (newlen != sizeof(int))
2503 return -EINVAL;
2504 if (get_user(new, (int __user *)newval))
2505 return -EFAULT;
2506 *(int *)(table->data) = new*HZ;
2508 return 1;
2511 /* Strategy function to convert jiffies to seconds */
2512 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2513 void __user *oldval, size_t __user *oldlenp,
2514 void __user *newval, size_t newlen)
2516 if (oldval && oldlenp) {
2517 size_t olen;
2519 if (get_user(olen, oldlenp))
2520 return -EFAULT;
2521 if (olen) {
2522 int val;
2524 if (olen < sizeof(int))
2525 return -EINVAL;
2527 val = jiffies_to_msecs(*(int *)(table->data));
2528 if (put_user(val, (int __user *)oldval))
2529 return -EFAULT;
2530 if (put_user(sizeof(int), oldlenp))
2531 return -EFAULT;
2534 if (newval && newlen) {
2535 int new;
2536 if (newlen != sizeof(int))
2537 return -EINVAL;
2538 if (get_user(new, (int __user *)newval))
2539 return -EFAULT;
2540 *(int *)(table->data) = msecs_to_jiffies(new);
2542 return 1;
2547 #else /* CONFIG_SYSCTL_SYSCALL */
2550 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2552 static int msg_count;
2553 struct __sysctl_args tmp;
2554 int name[CTL_MAXNAME];
2555 int i;
2557 /* Read in the sysctl name for better debug message logging */
2558 if (copy_from_user(&tmp, args, sizeof(tmp)))
2559 return -EFAULT;
2560 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2561 return -ENOTDIR;
2562 for (i = 0; i < tmp.nlen; i++)
2563 if (get_user(name[i], tmp.name + i))
2564 return -EFAULT;
2566 /* Ignore accesses to kernel.version */
2567 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2568 goto out;
2570 if (msg_count < 5) {
2571 msg_count++;
2572 printk(KERN_INFO
2573 "warning: process `%s' used the removed sysctl "
2574 "system call with ", current->comm);
2575 for (i = 0; i < tmp.nlen; i++)
2576 printk("%d.", name[i]);
2577 printk("\n");
2579 out:
2580 return -ENOSYS;
2583 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2584 void __user *oldval, size_t __user *oldlenp,
2585 void __user *newval, size_t newlen)
2587 return -ENOSYS;
2590 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2591 void __user *oldval, size_t __user *oldlenp,
2592 void __user *newval, size_t newlen)
2594 return -ENOSYS;
2597 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2598 void __user *oldval, size_t __user *oldlenp,
2599 void __user *newval, size_t newlen)
2601 return -ENOSYS;
2604 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2605 void __user *oldval, size_t __user *oldlenp,
2606 void __user *newval, size_t newlen)
2608 return -ENOSYS;
2611 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2612 void __user *oldval, size_t __user *oldlenp,
2613 void __user *newval, size_t newlen)
2615 return -ENOSYS;
2618 #endif /* CONFIG_SYSCTL_SYSCALL */
2621 * No sense putting this after each symbol definition, twice,
2622 * exception granted :-)
2624 EXPORT_SYMBOL(proc_dointvec);
2625 EXPORT_SYMBOL(proc_dointvec_jiffies);
2626 EXPORT_SYMBOL(proc_dointvec_minmax);
2627 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2628 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2629 EXPORT_SYMBOL(proc_dostring);
2630 EXPORT_SYMBOL(proc_doulongvec_minmax);
2631 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2632 EXPORT_SYMBOL(register_sysctl_table);
2633 EXPORT_SYMBOL(sysctl_intvec);
2634 EXPORT_SYMBOL(sysctl_jiffies);
2635 EXPORT_SYMBOL(sysctl_ms_jiffies);
2636 EXPORT_SYMBOL(sysctl_string);
2637 EXPORT_SYMBOL(sysctl_data);
2638 EXPORT_SYMBOL(unregister_sysctl_table);