sysctl: simplify the pty sysctl logic
[linux-2.6/mini2440.git] / kernel / sysctl.c
blob0278f52c4b04b019b74176a61dce2a89217a94e9
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_INOTIFY_USER
167 extern struct ctl_table inotify_table[];
168 #endif
170 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
171 int sysctl_legacy_va_layout;
172 #endif
174 extern int prove_locking;
175 extern int lock_stat;
177 /* The default sysctl tables: */
179 static struct ctl_table root_table[] = {
181 .ctl_name = CTL_KERN,
182 .procname = "kernel",
183 .mode = 0555,
184 .child = kern_table,
187 .ctl_name = CTL_VM,
188 .procname = "vm",
189 .mode = 0555,
190 .child = vm_table,
192 #ifdef CONFIG_NET
194 .ctl_name = CTL_NET,
195 .procname = "net",
196 .mode = 0555,
197 .child = net_table,
199 #endif
201 .ctl_name = CTL_FS,
202 .procname = "fs",
203 .mode = 0555,
204 .child = fs_table,
207 .ctl_name = CTL_DEBUG,
208 .procname = "debug",
209 .mode = 0555,
210 .child = debug_table,
213 .ctl_name = CTL_DEV,
214 .procname = "dev",
215 .mode = 0555,
216 .child = dev_table,
219 * NOTE: do not add new entries to this table unless you have read
220 * Documentation/sysctl/ctl_unnumbered.txt
222 { .ctl_name = 0 }
225 #ifdef CONFIG_SCHED_DEBUG
226 static unsigned long min_sched_granularity_ns = 100000; /* 100 usecs */
227 static unsigned long max_sched_granularity_ns = 1000000000; /* 1 second */
228 static unsigned long min_wakeup_granularity_ns; /* 0 usecs */
229 static unsigned long max_wakeup_granularity_ns = 1000000000; /* 1 second */
230 #endif
232 static struct ctl_table kern_table[] = {
233 #ifdef CONFIG_SCHED_DEBUG
235 .ctl_name = CTL_UNNUMBERED,
236 .procname = "sched_nr_latency",
237 .data = &sysctl_sched_nr_latency,
238 .maxlen = sizeof(unsigned int),
239 .mode = 0644,
240 .proc_handler = &proc_dointvec,
243 .ctl_name = CTL_UNNUMBERED,
244 .procname = "sched_latency_ns",
245 .data = &sysctl_sched_latency,
246 .maxlen = sizeof(unsigned int),
247 .mode = 0644,
248 .proc_handler = &proc_dointvec_minmax,
249 .strategy = &sysctl_intvec,
250 .extra1 = &min_sched_granularity_ns,
251 .extra2 = &max_sched_granularity_ns,
254 .ctl_name = CTL_UNNUMBERED,
255 .procname = "sched_wakeup_granularity_ns",
256 .data = &sysctl_sched_wakeup_granularity,
257 .maxlen = sizeof(unsigned int),
258 .mode = 0644,
259 .proc_handler = &proc_dointvec_minmax,
260 .strategy = &sysctl_intvec,
261 .extra1 = &min_wakeup_granularity_ns,
262 .extra2 = &max_wakeup_granularity_ns,
265 .ctl_name = CTL_UNNUMBERED,
266 .procname = "sched_batch_wakeup_granularity_ns",
267 .data = &sysctl_sched_batch_wakeup_granularity,
268 .maxlen = sizeof(unsigned int),
269 .mode = 0644,
270 .proc_handler = &proc_dointvec_minmax,
271 .strategy = &sysctl_intvec,
272 .extra1 = &min_wakeup_granularity_ns,
273 .extra2 = &max_wakeup_granularity_ns,
276 .ctl_name = CTL_UNNUMBERED,
277 .procname = "sched_child_runs_first",
278 .data = &sysctl_sched_child_runs_first,
279 .maxlen = sizeof(unsigned int),
280 .mode = 0644,
281 .proc_handler = &proc_dointvec,
284 .ctl_name = CTL_UNNUMBERED,
285 .procname = "sched_features",
286 .data = &sysctl_sched_features,
287 .maxlen = sizeof(unsigned int),
288 .mode = 0644,
289 .proc_handler = &proc_dointvec,
292 .ctl_name = CTL_UNNUMBERED,
293 .procname = "sched_migration_cost",
294 .data = &sysctl_sched_migration_cost,
295 .maxlen = sizeof(unsigned int),
296 .mode = 0644,
297 .proc_handler = &proc_dointvec,
299 #endif
301 .ctl_name = CTL_UNNUMBERED,
302 .procname = "sched_compat_yield",
303 .data = &sysctl_sched_compat_yield,
304 .maxlen = sizeof(unsigned int),
305 .mode = 0644,
306 .proc_handler = &proc_dointvec,
308 #ifdef CONFIG_PROVE_LOCKING
310 .ctl_name = CTL_UNNUMBERED,
311 .procname = "prove_locking",
312 .data = &prove_locking,
313 .maxlen = sizeof(int),
314 .mode = 0644,
315 .proc_handler = &proc_dointvec,
317 #endif
318 #ifdef CONFIG_LOCK_STAT
320 .ctl_name = CTL_UNNUMBERED,
321 .procname = "lock_stat",
322 .data = &lock_stat,
323 .maxlen = sizeof(int),
324 .mode = 0644,
325 .proc_handler = &proc_dointvec,
327 #endif
329 .ctl_name = KERN_PANIC,
330 .procname = "panic",
331 .data = &panic_timeout,
332 .maxlen = sizeof(int),
333 .mode = 0644,
334 .proc_handler = &proc_dointvec,
337 .ctl_name = KERN_CORE_USES_PID,
338 .procname = "core_uses_pid",
339 .data = &core_uses_pid,
340 .maxlen = sizeof(int),
341 .mode = 0644,
342 .proc_handler = &proc_dointvec,
344 #ifdef CONFIG_AUDITSYSCALL
346 .ctl_name = CTL_UNNUMBERED,
347 .procname = "audit_argv_kb",
348 .data = &audit_argv_kb,
349 .maxlen = sizeof(int),
350 .mode = 0644,
351 .proc_handler = &proc_dointvec,
353 #endif
355 .ctl_name = KERN_CORE_PATTERN,
356 .procname = "core_pattern",
357 .data = core_pattern,
358 .maxlen = CORENAME_MAX_SIZE,
359 .mode = 0644,
360 .proc_handler = &proc_dostring,
361 .strategy = &sysctl_string,
363 #ifdef CONFIG_PROC_SYSCTL
365 .procname = "tainted",
366 .data = &tainted,
367 .maxlen = sizeof(int),
368 .mode = 0644,
369 .proc_handler = &proc_dointvec_taint,
371 #endif
373 .procname = "cap-bound",
374 .data = &cap_bset,
375 .maxlen = sizeof(kernel_cap_t),
376 .mode = 0600,
377 .proc_handler = &proc_dointvec_bset,
379 #ifdef CONFIG_BLK_DEV_INITRD
381 .ctl_name = KERN_REALROOTDEV,
382 .procname = "real-root-dev",
383 .data = &real_root_dev,
384 .maxlen = sizeof(int),
385 .mode = 0644,
386 .proc_handler = &proc_dointvec,
388 #endif
390 .ctl_name = CTL_UNNUMBERED,
391 .procname = "print-fatal-signals",
392 .data = &print_fatal_signals,
393 .maxlen = sizeof(int),
394 .mode = 0644,
395 .proc_handler = &proc_dointvec,
397 #ifdef __sparc__
399 .ctl_name = KERN_SPARC_REBOOT,
400 .procname = "reboot-cmd",
401 .data = reboot_command,
402 .maxlen = 256,
403 .mode = 0644,
404 .proc_handler = &proc_dostring,
405 .strategy = &sysctl_string,
408 .ctl_name = KERN_SPARC_STOP_A,
409 .procname = "stop-a",
410 .data = &stop_a_enabled,
411 .maxlen = sizeof (int),
412 .mode = 0644,
413 .proc_handler = &proc_dointvec,
416 .ctl_name = KERN_SPARC_SCONS_PWROFF,
417 .procname = "scons-poweroff",
418 .data = &scons_pwroff,
419 .maxlen = sizeof (int),
420 .mode = 0644,
421 .proc_handler = &proc_dointvec,
423 #endif
424 #ifdef __hppa__
426 .ctl_name = KERN_HPPA_PWRSW,
427 .procname = "soft-power",
428 .data = &pwrsw_enabled,
429 .maxlen = sizeof (int),
430 .mode = 0644,
431 .proc_handler = &proc_dointvec,
434 .ctl_name = KERN_HPPA_UNALIGNED,
435 .procname = "unaligned-trap",
436 .data = &unaligned_enabled,
437 .maxlen = sizeof (int),
438 .mode = 0644,
439 .proc_handler = &proc_dointvec,
441 #endif
443 .ctl_name = KERN_CTLALTDEL,
444 .procname = "ctrl-alt-del",
445 .data = &C_A_D,
446 .maxlen = sizeof(int),
447 .mode = 0644,
448 .proc_handler = &proc_dointvec,
451 .ctl_name = KERN_PRINTK,
452 .procname = "printk",
453 .data = &console_loglevel,
454 .maxlen = 4*sizeof(int),
455 .mode = 0644,
456 .proc_handler = &proc_dointvec,
458 #ifdef CONFIG_KMOD
460 .ctl_name = KERN_MODPROBE,
461 .procname = "modprobe",
462 .data = &modprobe_path,
463 .maxlen = KMOD_PATH_LEN,
464 .mode = 0644,
465 .proc_handler = &proc_dostring,
466 .strategy = &sysctl_string,
468 #endif
469 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
471 .ctl_name = KERN_HOTPLUG,
472 .procname = "hotplug",
473 .data = &uevent_helper,
474 .maxlen = UEVENT_HELPER_PATH_LEN,
475 .mode = 0644,
476 .proc_handler = &proc_dostring,
477 .strategy = &sysctl_string,
479 #endif
480 #ifdef CONFIG_CHR_DEV_SG
482 .ctl_name = KERN_SG_BIG_BUFF,
483 .procname = "sg-big-buff",
484 .data = &sg_big_buff,
485 .maxlen = sizeof (int),
486 .mode = 0444,
487 .proc_handler = &proc_dointvec,
489 #endif
490 #ifdef CONFIG_BSD_PROCESS_ACCT
492 .ctl_name = KERN_ACCT,
493 .procname = "acct",
494 .data = &acct_parm,
495 .maxlen = 3*sizeof(int),
496 .mode = 0644,
497 .proc_handler = &proc_dointvec,
499 #endif
500 #ifdef CONFIG_MAGIC_SYSRQ
502 .ctl_name = KERN_SYSRQ,
503 .procname = "sysrq",
504 .data = &__sysrq_enabled,
505 .maxlen = sizeof (int),
506 .mode = 0644,
507 .proc_handler = &proc_dointvec,
509 #endif
510 #ifdef CONFIG_PROC_SYSCTL
512 .ctl_name = KERN_CADPID,
513 .procname = "cad_pid",
514 .data = NULL,
515 .maxlen = sizeof (int),
516 .mode = 0600,
517 .proc_handler = &proc_do_cad_pid,
519 #endif
521 .ctl_name = KERN_MAX_THREADS,
522 .procname = "threads-max",
523 .data = &max_threads,
524 .maxlen = sizeof(int),
525 .mode = 0644,
526 .proc_handler = &proc_dointvec,
529 .ctl_name = KERN_RANDOM,
530 .procname = "random",
531 .mode = 0555,
532 .child = random_table,
535 .ctl_name = KERN_OVERFLOWUID,
536 .procname = "overflowuid",
537 .data = &overflowuid,
538 .maxlen = sizeof(int),
539 .mode = 0644,
540 .proc_handler = &proc_dointvec_minmax,
541 .strategy = &sysctl_intvec,
542 .extra1 = &minolduid,
543 .extra2 = &maxolduid,
546 .ctl_name = KERN_OVERFLOWGID,
547 .procname = "overflowgid",
548 .data = &overflowgid,
549 .maxlen = sizeof(int),
550 .mode = 0644,
551 .proc_handler = &proc_dointvec_minmax,
552 .strategy = &sysctl_intvec,
553 .extra1 = &minolduid,
554 .extra2 = &maxolduid,
556 #ifdef CONFIG_S390
557 #ifdef CONFIG_MATHEMU
559 .ctl_name = KERN_IEEE_EMULATION_WARNINGS,
560 .procname = "ieee_emulation_warnings",
561 .data = &sysctl_ieee_emulation_warnings,
562 .maxlen = sizeof(int),
563 .mode = 0644,
564 .proc_handler = &proc_dointvec,
566 #endif
567 #ifdef CONFIG_NO_IDLE_HZ
569 .ctl_name = KERN_HZ_TIMER,
570 .procname = "hz_timer",
571 .data = &sysctl_hz_timer,
572 .maxlen = sizeof(int),
573 .mode = 0644,
574 .proc_handler = &proc_dointvec,
576 #endif
578 .ctl_name = KERN_S390_USER_DEBUG_LOGGING,
579 .procname = "userprocess_debug",
580 .data = &sysctl_userprocess_debug,
581 .maxlen = sizeof(int),
582 .mode = 0644,
583 .proc_handler = &proc_dointvec,
585 #endif
587 .ctl_name = KERN_PIDMAX,
588 .procname = "pid_max",
589 .data = &pid_max,
590 .maxlen = sizeof (int),
591 .mode = 0644,
592 .proc_handler = &proc_dointvec_minmax,
593 .strategy = sysctl_intvec,
594 .extra1 = &pid_max_min,
595 .extra2 = &pid_max_max,
598 .ctl_name = KERN_PANIC_ON_OOPS,
599 .procname = "panic_on_oops",
600 .data = &panic_on_oops,
601 .maxlen = sizeof(int),
602 .mode = 0644,
603 .proc_handler = &proc_dointvec,
606 .ctl_name = KERN_PRINTK_RATELIMIT,
607 .procname = "printk_ratelimit",
608 .data = &printk_ratelimit_jiffies,
609 .maxlen = sizeof(int),
610 .mode = 0644,
611 .proc_handler = &proc_dointvec_jiffies,
612 .strategy = &sysctl_jiffies,
615 .ctl_name = KERN_PRINTK_RATELIMIT_BURST,
616 .procname = "printk_ratelimit_burst",
617 .data = &printk_ratelimit_burst,
618 .maxlen = sizeof(int),
619 .mode = 0644,
620 .proc_handler = &proc_dointvec,
623 .ctl_name = KERN_NGROUPS_MAX,
624 .procname = "ngroups_max",
625 .data = &ngroups_max,
626 .maxlen = sizeof (int),
627 .mode = 0444,
628 .proc_handler = &proc_dointvec,
630 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
632 .ctl_name = KERN_UNKNOWN_NMI_PANIC,
633 .procname = "unknown_nmi_panic",
634 .data = &unknown_nmi_panic,
635 .maxlen = sizeof (int),
636 .mode = 0644,
637 .proc_handler = &proc_dointvec,
640 .procname = "nmi_watchdog",
641 .data = &nmi_watchdog_enabled,
642 .maxlen = sizeof (int),
643 .mode = 0644,
644 .proc_handler = &proc_nmi_enabled,
646 #endif
647 #if defined(CONFIG_X86)
649 .ctl_name = KERN_PANIC_ON_NMI,
650 .procname = "panic_on_unrecovered_nmi",
651 .data = &panic_on_unrecovered_nmi,
652 .maxlen = sizeof(int),
653 .mode = 0644,
654 .proc_handler = &proc_dointvec,
657 .ctl_name = KERN_BOOTLOADER_TYPE,
658 .procname = "bootloader_type",
659 .data = &bootloader_type,
660 .maxlen = sizeof (int),
661 .mode = 0444,
662 .proc_handler = &proc_dointvec,
665 .ctl_name = CTL_UNNUMBERED,
666 .procname = "kstack_depth_to_print",
667 .data = &kstack_depth_to_print,
668 .maxlen = sizeof(int),
669 .mode = 0644,
670 .proc_handler = &proc_dointvec,
672 #endif
673 #if defined(CONFIG_MMU)
675 .ctl_name = KERN_RANDOMIZE,
676 .procname = "randomize_va_space",
677 .data = &randomize_va_space,
678 .maxlen = sizeof(int),
679 .mode = 0644,
680 .proc_handler = &proc_dointvec,
682 #endif
683 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
685 .ctl_name = KERN_SPIN_RETRY,
686 .procname = "spin_retry",
687 .data = &spin_retry,
688 .maxlen = sizeof (int),
689 .mode = 0644,
690 .proc_handler = &proc_dointvec,
692 #endif
693 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
695 .procname = "acpi_video_flags",
696 .data = &acpi_realmode_flags,
697 .maxlen = sizeof (unsigned long),
698 .mode = 0644,
699 .proc_handler = &proc_doulongvec_minmax,
701 #endif
702 #ifdef CONFIG_IA64
704 .ctl_name = KERN_IA64_UNALIGNED,
705 .procname = "ignore-unaligned-usertrap",
706 .data = &no_unaligned_warning,
707 .maxlen = sizeof (int),
708 .mode = 0644,
709 .proc_handler = &proc_dointvec,
711 #endif
712 #ifdef CONFIG_DETECT_SOFTLOCKUP
714 .ctl_name = CTL_UNNUMBERED,
715 .procname = "softlockup_thresh",
716 .data = &softlockup_thresh,
717 .maxlen = sizeof(int),
718 .mode = 0644,
719 .proc_handler = &proc_dointvec_minmax,
720 .strategy = &sysctl_intvec,
721 .extra1 = &one,
722 .extra2 = &sixty,
724 #endif
725 #ifdef CONFIG_COMPAT
727 .ctl_name = KERN_COMPAT_LOG,
728 .procname = "compat-log",
729 .data = &compat_log,
730 .maxlen = sizeof (int),
731 .mode = 0644,
732 .proc_handler = &proc_dointvec,
734 #endif
735 #ifdef CONFIG_RT_MUTEXES
737 .ctl_name = KERN_MAX_LOCK_DEPTH,
738 .procname = "max_lock_depth",
739 .data = &max_lock_depth,
740 .maxlen = sizeof(int),
741 .mode = 0644,
742 .proc_handler = &proc_dointvec,
744 #endif
745 #ifdef CONFIG_PROC_FS
747 .ctl_name = CTL_UNNUMBERED,
748 .procname = "maps_protect",
749 .data = &maps_protect,
750 .maxlen = sizeof(int),
751 .mode = 0644,
752 .proc_handler = &proc_dointvec,
754 #endif
756 .ctl_name = CTL_UNNUMBERED,
757 .procname = "poweroff_cmd",
758 .data = &poweroff_cmd,
759 .maxlen = POWEROFF_CMD_PATH_LEN,
760 .mode = 0644,
761 .proc_handler = &proc_dostring,
762 .strategy = &sysctl_string,
765 * NOTE: do not add new entries to this table unless you have read
766 * Documentation/sysctl/ctl_unnumbered.txt
768 { .ctl_name = 0 }
771 static struct ctl_table vm_table[] = {
773 .ctl_name = VM_OVERCOMMIT_MEMORY,
774 .procname = "overcommit_memory",
775 .data = &sysctl_overcommit_memory,
776 .maxlen = sizeof(sysctl_overcommit_memory),
777 .mode = 0644,
778 .proc_handler = &proc_dointvec,
781 .ctl_name = VM_PANIC_ON_OOM,
782 .procname = "panic_on_oom",
783 .data = &sysctl_panic_on_oom,
784 .maxlen = sizeof(sysctl_panic_on_oom),
785 .mode = 0644,
786 .proc_handler = &proc_dointvec,
789 .ctl_name = CTL_UNNUMBERED,
790 .procname = "oom_kill_allocating_task",
791 .data = &sysctl_oom_kill_allocating_task,
792 .maxlen = sizeof(sysctl_oom_kill_allocating_task),
793 .mode = 0644,
794 .proc_handler = &proc_dointvec,
797 .ctl_name = VM_OVERCOMMIT_RATIO,
798 .procname = "overcommit_ratio",
799 .data = &sysctl_overcommit_ratio,
800 .maxlen = sizeof(sysctl_overcommit_ratio),
801 .mode = 0644,
802 .proc_handler = &proc_dointvec,
805 .ctl_name = VM_PAGE_CLUSTER,
806 .procname = "page-cluster",
807 .data = &page_cluster,
808 .maxlen = sizeof(int),
809 .mode = 0644,
810 .proc_handler = &proc_dointvec,
813 .ctl_name = VM_DIRTY_BACKGROUND,
814 .procname = "dirty_background_ratio",
815 .data = &dirty_background_ratio,
816 .maxlen = sizeof(dirty_background_ratio),
817 .mode = 0644,
818 .proc_handler = &proc_dointvec_minmax,
819 .strategy = &sysctl_intvec,
820 .extra1 = &zero,
821 .extra2 = &one_hundred,
824 .ctl_name = VM_DIRTY_RATIO,
825 .procname = "dirty_ratio",
826 .data = &vm_dirty_ratio,
827 .maxlen = sizeof(vm_dirty_ratio),
828 .mode = 0644,
829 .proc_handler = &dirty_ratio_handler,
830 .strategy = &sysctl_intvec,
831 .extra1 = &zero,
832 .extra2 = &one_hundred,
835 .procname = "dirty_writeback_centisecs",
836 .data = &dirty_writeback_interval,
837 .maxlen = sizeof(dirty_writeback_interval),
838 .mode = 0644,
839 .proc_handler = &dirty_writeback_centisecs_handler,
842 .procname = "dirty_expire_centisecs",
843 .data = &dirty_expire_interval,
844 .maxlen = sizeof(dirty_expire_interval),
845 .mode = 0644,
846 .proc_handler = &proc_dointvec_userhz_jiffies,
849 .ctl_name = VM_NR_PDFLUSH_THREADS,
850 .procname = "nr_pdflush_threads",
851 .data = &nr_pdflush_threads,
852 .maxlen = sizeof nr_pdflush_threads,
853 .mode = 0444 /* read-only*/,
854 .proc_handler = &proc_dointvec,
857 .ctl_name = VM_SWAPPINESS,
858 .procname = "swappiness",
859 .data = &vm_swappiness,
860 .maxlen = sizeof(vm_swappiness),
861 .mode = 0644,
862 .proc_handler = &proc_dointvec_minmax,
863 .strategy = &sysctl_intvec,
864 .extra1 = &zero,
865 .extra2 = &one_hundred,
867 #ifdef CONFIG_HUGETLB_PAGE
869 .procname = "nr_hugepages",
870 .data = &max_huge_pages,
871 .maxlen = sizeof(unsigned long),
872 .mode = 0644,
873 .proc_handler = &hugetlb_sysctl_handler,
874 .extra1 = (void *)&hugetlb_zero,
875 .extra2 = (void *)&hugetlb_infinity,
878 .ctl_name = VM_HUGETLB_GROUP,
879 .procname = "hugetlb_shm_group",
880 .data = &sysctl_hugetlb_shm_group,
881 .maxlen = sizeof(gid_t),
882 .mode = 0644,
883 .proc_handler = &proc_dointvec,
886 .ctl_name = CTL_UNNUMBERED,
887 .procname = "hugepages_treat_as_movable",
888 .data = &hugepages_treat_as_movable,
889 .maxlen = sizeof(int),
890 .mode = 0644,
891 .proc_handler = &hugetlb_treat_movable_handler,
894 .ctl_name = CTL_UNNUMBERED,
895 .procname = "hugetlb_dynamic_pool",
896 .data = &hugetlb_dynamic_pool,
897 .maxlen = sizeof(hugetlb_dynamic_pool),
898 .mode = 0644,
899 .proc_handler = &proc_dointvec,
901 #endif
903 .ctl_name = VM_LOWMEM_RESERVE_RATIO,
904 .procname = "lowmem_reserve_ratio",
905 .data = &sysctl_lowmem_reserve_ratio,
906 .maxlen = sizeof(sysctl_lowmem_reserve_ratio),
907 .mode = 0644,
908 .proc_handler = &lowmem_reserve_ratio_sysctl_handler,
909 .strategy = &sysctl_intvec,
912 .ctl_name = VM_DROP_PAGECACHE,
913 .procname = "drop_caches",
914 .data = &sysctl_drop_caches,
915 .maxlen = sizeof(int),
916 .mode = 0644,
917 .proc_handler = drop_caches_sysctl_handler,
918 .strategy = &sysctl_intvec,
921 .ctl_name = VM_MIN_FREE_KBYTES,
922 .procname = "min_free_kbytes",
923 .data = &min_free_kbytes,
924 .maxlen = sizeof(min_free_kbytes),
925 .mode = 0644,
926 .proc_handler = &min_free_kbytes_sysctl_handler,
927 .strategy = &sysctl_intvec,
928 .extra1 = &zero,
931 .ctl_name = VM_PERCPU_PAGELIST_FRACTION,
932 .procname = "percpu_pagelist_fraction",
933 .data = &percpu_pagelist_fraction,
934 .maxlen = sizeof(percpu_pagelist_fraction),
935 .mode = 0644,
936 .proc_handler = &percpu_pagelist_fraction_sysctl_handler,
937 .strategy = &sysctl_intvec,
938 .extra1 = &min_percpu_pagelist_fract,
940 #ifdef CONFIG_MMU
942 .ctl_name = VM_MAX_MAP_COUNT,
943 .procname = "max_map_count",
944 .data = &sysctl_max_map_count,
945 .maxlen = sizeof(sysctl_max_map_count),
946 .mode = 0644,
947 .proc_handler = &proc_dointvec
949 #endif
951 .ctl_name = VM_LAPTOP_MODE,
952 .procname = "laptop_mode",
953 .data = &laptop_mode,
954 .maxlen = sizeof(laptop_mode),
955 .mode = 0644,
956 .proc_handler = &proc_dointvec_jiffies,
957 .strategy = &sysctl_jiffies,
960 .ctl_name = VM_BLOCK_DUMP,
961 .procname = "block_dump",
962 .data = &block_dump,
963 .maxlen = sizeof(block_dump),
964 .mode = 0644,
965 .proc_handler = &proc_dointvec,
966 .strategy = &sysctl_intvec,
967 .extra1 = &zero,
970 .ctl_name = VM_VFS_CACHE_PRESSURE,
971 .procname = "vfs_cache_pressure",
972 .data = &sysctl_vfs_cache_pressure,
973 .maxlen = sizeof(sysctl_vfs_cache_pressure),
974 .mode = 0644,
975 .proc_handler = &proc_dointvec,
976 .strategy = &sysctl_intvec,
977 .extra1 = &zero,
979 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
981 .ctl_name = VM_LEGACY_VA_LAYOUT,
982 .procname = "legacy_va_layout",
983 .data = &sysctl_legacy_va_layout,
984 .maxlen = sizeof(sysctl_legacy_va_layout),
985 .mode = 0644,
986 .proc_handler = &proc_dointvec,
987 .strategy = &sysctl_intvec,
988 .extra1 = &zero,
990 #endif
991 #ifdef CONFIG_NUMA
993 .ctl_name = VM_ZONE_RECLAIM_MODE,
994 .procname = "zone_reclaim_mode",
995 .data = &zone_reclaim_mode,
996 .maxlen = sizeof(zone_reclaim_mode),
997 .mode = 0644,
998 .proc_handler = &proc_dointvec,
999 .strategy = &sysctl_intvec,
1000 .extra1 = &zero,
1003 .ctl_name = VM_MIN_UNMAPPED,
1004 .procname = "min_unmapped_ratio",
1005 .data = &sysctl_min_unmapped_ratio,
1006 .maxlen = sizeof(sysctl_min_unmapped_ratio),
1007 .mode = 0644,
1008 .proc_handler = &sysctl_min_unmapped_ratio_sysctl_handler,
1009 .strategy = &sysctl_intvec,
1010 .extra1 = &zero,
1011 .extra2 = &one_hundred,
1014 .ctl_name = VM_MIN_SLAB,
1015 .procname = "min_slab_ratio",
1016 .data = &sysctl_min_slab_ratio,
1017 .maxlen = sizeof(sysctl_min_slab_ratio),
1018 .mode = 0644,
1019 .proc_handler = &sysctl_min_slab_ratio_sysctl_handler,
1020 .strategy = &sysctl_intvec,
1021 .extra1 = &zero,
1022 .extra2 = &one_hundred,
1024 #endif
1025 #ifdef CONFIG_SMP
1027 .ctl_name = CTL_UNNUMBERED,
1028 .procname = "stat_interval",
1029 .data = &sysctl_stat_interval,
1030 .maxlen = sizeof(sysctl_stat_interval),
1031 .mode = 0644,
1032 .proc_handler = &proc_dointvec_jiffies,
1033 .strategy = &sysctl_jiffies,
1035 #endif
1036 #ifdef CONFIG_SECURITY
1038 .ctl_name = CTL_UNNUMBERED,
1039 .procname = "mmap_min_addr",
1040 .data = &mmap_min_addr,
1041 .maxlen = sizeof(unsigned long),
1042 .mode = 0644,
1043 .proc_handler = &proc_doulongvec_minmax,
1045 #endif
1046 #ifdef CONFIG_NUMA
1048 .ctl_name = CTL_UNNUMBERED,
1049 .procname = "numa_zonelist_order",
1050 .data = &numa_zonelist_order,
1051 .maxlen = NUMA_ZONELIST_ORDER_LEN,
1052 .mode = 0644,
1053 .proc_handler = &numa_zonelist_order_handler,
1054 .strategy = &sysctl_string,
1056 #endif
1057 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1058 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1060 .ctl_name = VM_VDSO_ENABLED,
1061 .procname = "vdso_enabled",
1062 .data = &vdso_enabled,
1063 .maxlen = sizeof(vdso_enabled),
1064 .mode = 0644,
1065 .proc_handler = &proc_dointvec,
1066 .strategy = &sysctl_intvec,
1067 .extra1 = &zero,
1069 #endif
1071 * NOTE: do not add new entries to this table unless you have read
1072 * Documentation/sysctl/ctl_unnumbered.txt
1074 { .ctl_name = 0 }
1077 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1078 static struct ctl_table binfmt_misc_table[] = {
1079 { .ctl_name = 0 }
1081 #endif
1083 static struct ctl_table fs_table[] = {
1085 .ctl_name = FS_NRINODE,
1086 .procname = "inode-nr",
1087 .data = &inodes_stat,
1088 .maxlen = 2*sizeof(int),
1089 .mode = 0444,
1090 .proc_handler = &proc_dointvec,
1093 .ctl_name = FS_STATINODE,
1094 .procname = "inode-state",
1095 .data = &inodes_stat,
1096 .maxlen = 7*sizeof(int),
1097 .mode = 0444,
1098 .proc_handler = &proc_dointvec,
1101 .procname = "file-nr",
1102 .data = &files_stat,
1103 .maxlen = 3*sizeof(int),
1104 .mode = 0444,
1105 .proc_handler = &proc_nr_files,
1108 .ctl_name = FS_MAXFILE,
1109 .procname = "file-max",
1110 .data = &files_stat.max_files,
1111 .maxlen = sizeof(int),
1112 .mode = 0644,
1113 .proc_handler = &proc_dointvec,
1116 .ctl_name = FS_DENTRY,
1117 .procname = "dentry-state",
1118 .data = &dentry_stat,
1119 .maxlen = 6*sizeof(int),
1120 .mode = 0444,
1121 .proc_handler = &proc_dointvec,
1124 .ctl_name = FS_OVERFLOWUID,
1125 .procname = "overflowuid",
1126 .data = &fs_overflowuid,
1127 .maxlen = sizeof(int),
1128 .mode = 0644,
1129 .proc_handler = &proc_dointvec_minmax,
1130 .strategy = &sysctl_intvec,
1131 .extra1 = &minolduid,
1132 .extra2 = &maxolduid,
1135 .ctl_name = FS_OVERFLOWGID,
1136 .procname = "overflowgid",
1137 .data = &fs_overflowgid,
1138 .maxlen = sizeof(int),
1139 .mode = 0644,
1140 .proc_handler = &proc_dointvec_minmax,
1141 .strategy = &sysctl_intvec,
1142 .extra1 = &minolduid,
1143 .extra2 = &maxolduid,
1146 .ctl_name = FS_LEASES,
1147 .procname = "leases-enable",
1148 .data = &leases_enable,
1149 .maxlen = sizeof(int),
1150 .mode = 0644,
1151 .proc_handler = &proc_dointvec,
1153 #ifdef CONFIG_DNOTIFY
1155 .ctl_name = FS_DIR_NOTIFY,
1156 .procname = "dir-notify-enable",
1157 .data = &dir_notify_enable,
1158 .maxlen = sizeof(int),
1159 .mode = 0644,
1160 .proc_handler = &proc_dointvec,
1162 #endif
1163 #ifdef CONFIG_MMU
1165 .ctl_name = FS_LEASE_TIME,
1166 .procname = "lease-break-time",
1167 .data = &lease_break_time,
1168 .maxlen = sizeof(int),
1169 .mode = 0644,
1170 .proc_handler = &proc_dointvec_minmax,
1171 .strategy = &sysctl_intvec,
1172 .extra1 = &zero,
1173 .extra2 = &two,
1176 .procname = "aio-nr",
1177 .data = &aio_nr,
1178 .maxlen = sizeof(aio_nr),
1179 .mode = 0444,
1180 .proc_handler = &proc_doulongvec_minmax,
1183 .procname = "aio-max-nr",
1184 .data = &aio_max_nr,
1185 .maxlen = sizeof(aio_max_nr),
1186 .mode = 0644,
1187 .proc_handler = &proc_doulongvec_minmax,
1189 #ifdef CONFIG_INOTIFY_USER
1191 .ctl_name = FS_INOTIFY,
1192 .procname = "inotify",
1193 .mode = 0555,
1194 .child = inotify_table,
1196 #endif
1197 #endif
1199 .ctl_name = KERN_SETUID_DUMPABLE,
1200 .procname = "suid_dumpable",
1201 .data = &suid_dumpable,
1202 .maxlen = sizeof(int),
1203 .mode = 0644,
1204 .proc_handler = &proc_dointvec,
1206 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1208 .ctl_name = CTL_UNNUMBERED,
1209 .procname = "binfmt_misc",
1210 .mode = 0555,
1211 .child = binfmt_misc_table,
1213 #endif
1215 * NOTE: do not add new entries to this table unless you have read
1216 * Documentation/sysctl/ctl_unnumbered.txt
1218 { .ctl_name = 0 }
1221 static struct ctl_table debug_table[] = {
1222 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1224 .ctl_name = CTL_UNNUMBERED,
1225 .procname = "exception-trace",
1226 .data = &show_unhandled_signals,
1227 .maxlen = sizeof(int),
1228 .mode = 0644,
1229 .proc_handler = proc_dointvec
1231 #endif
1232 { .ctl_name = 0 }
1235 static struct ctl_table dev_table[] = {
1236 { .ctl_name = 0 }
1239 static DEFINE_SPINLOCK(sysctl_lock);
1241 /* called under sysctl_lock */
1242 static int use_table(struct ctl_table_header *p)
1244 if (unlikely(p->unregistering))
1245 return 0;
1246 p->used++;
1247 return 1;
1250 /* called under sysctl_lock */
1251 static void unuse_table(struct ctl_table_header *p)
1253 if (!--p->used)
1254 if (unlikely(p->unregistering))
1255 complete(p->unregistering);
1258 /* called under sysctl_lock, will reacquire if has to wait */
1259 static void start_unregistering(struct ctl_table_header *p)
1262 * if p->used is 0, nobody will ever touch that entry again;
1263 * we'll eliminate all paths to it before dropping sysctl_lock
1265 if (unlikely(p->used)) {
1266 struct completion wait;
1267 init_completion(&wait);
1268 p->unregistering = &wait;
1269 spin_unlock(&sysctl_lock);
1270 wait_for_completion(&wait);
1271 spin_lock(&sysctl_lock);
1274 * do not remove from the list until nobody holds it; walking the
1275 * list in do_sysctl() relies on that.
1277 list_del_init(&p->ctl_entry);
1280 void sysctl_head_finish(struct ctl_table_header *head)
1282 if (!head)
1283 return;
1284 spin_lock(&sysctl_lock);
1285 unuse_table(head);
1286 spin_unlock(&sysctl_lock);
1289 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1291 struct ctl_table_header *head;
1292 struct list_head *tmp;
1293 spin_lock(&sysctl_lock);
1294 if (prev) {
1295 tmp = &prev->ctl_entry;
1296 unuse_table(prev);
1297 goto next;
1299 tmp = &root_table_header.ctl_entry;
1300 for (;;) {
1301 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1303 if (!use_table(head))
1304 goto next;
1305 spin_unlock(&sysctl_lock);
1306 return head;
1307 next:
1308 tmp = tmp->next;
1309 if (tmp == &root_table_header.ctl_entry)
1310 break;
1312 spin_unlock(&sysctl_lock);
1313 return NULL;
1316 #ifdef CONFIG_SYSCTL_SYSCALL
1317 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1318 void __user *newval, size_t newlen)
1320 struct ctl_table_header *head;
1321 int error = -ENOTDIR;
1323 if (nlen <= 0 || nlen >= CTL_MAXNAME)
1324 return -ENOTDIR;
1325 if (oldval) {
1326 int old_len;
1327 if (!oldlenp || get_user(old_len, oldlenp))
1328 return -EFAULT;
1331 for (head = sysctl_head_next(NULL); head;
1332 head = sysctl_head_next(head)) {
1333 error = parse_table(name, nlen, oldval, oldlenp,
1334 newval, newlen, head->ctl_table);
1335 if (error != -ENOTDIR) {
1336 sysctl_head_finish(head);
1337 break;
1340 return error;
1343 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1345 struct __sysctl_args tmp;
1346 int error;
1348 if (copy_from_user(&tmp, args, sizeof(tmp)))
1349 return -EFAULT;
1351 lock_kernel();
1352 error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1353 tmp.newval, tmp.newlen);
1354 unlock_kernel();
1355 return error;
1357 #endif /* CONFIG_SYSCTL_SYSCALL */
1360 * sysctl_perm does NOT grant the superuser all rights automatically, because
1361 * some sysctl variables are readonly even to root.
1364 static int test_perm(int mode, int op)
1366 if (!current->euid)
1367 mode >>= 6;
1368 else if (in_egroup_p(0))
1369 mode >>= 3;
1370 if ((mode & op & 0007) == op)
1371 return 0;
1372 return -EACCES;
1375 int sysctl_perm(struct ctl_table *table, int op)
1377 int error;
1378 error = security_sysctl(table, op);
1379 if (error)
1380 return error;
1381 return test_perm(table->mode, op);
1384 #ifdef CONFIG_SYSCTL_SYSCALL
1385 static int parse_table(int __user *name, int nlen,
1386 void __user *oldval, size_t __user *oldlenp,
1387 void __user *newval, size_t newlen,
1388 struct ctl_table *table)
1390 int n;
1391 repeat:
1392 if (!nlen)
1393 return -ENOTDIR;
1394 if (get_user(n, name))
1395 return -EFAULT;
1396 for ( ; table->ctl_name || table->procname; table++) {
1397 if (!table->ctl_name)
1398 continue;
1399 if (n == table->ctl_name) {
1400 int error;
1401 if (table->child) {
1402 if (sysctl_perm(table, 001))
1403 return -EPERM;
1404 name++;
1405 nlen--;
1406 table = table->child;
1407 goto repeat;
1409 error = do_sysctl_strategy(table, name, nlen,
1410 oldval, oldlenp,
1411 newval, newlen);
1412 return error;
1415 return -ENOTDIR;
1418 /* Perform the actual read/write of a sysctl table entry. */
1419 int do_sysctl_strategy (struct ctl_table *table,
1420 int __user *name, int nlen,
1421 void __user *oldval, size_t __user *oldlenp,
1422 void __user *newval, size_t newlen)
1424 int op = 0, rc;
1426 if (oldval)
1427 op |= 004;
1428 if (newval)
1429 op |= 002;
1430 if (sysctl_perm(table, op))
1431 return -EPERM;
1433 if (table->strategy) {
1434 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1435 newval, newlen);
1436 if (rc < 0)
1437 return rc;
1438 if (rc > 0)
1439 return 0;
1442 /* If there is no strategy routine, or if the strategy returns
1443 * zero, proceed with automatic r/w */
1444 if (table->data && table->maxlen) {
1445 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1446 newval, newlen);
1447 if (rc < 0)
1448 return rc;
1450 return 0;
1452 #endif /* CONFIG_SYSCTL_SYSCALL */
1454 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1456 for (; table->ctl_name || table->procname; table++) {
1457 table->parent = parent;
1458 if (table->child)
1459 sysctl_set_parent(table, table->child);
1463 static __init int sysctl_init(void)
1465 sysctl_set_parent(NULL, root_table);
1466 return 0;
1469 core_initcall(sysctl_init);
1472 * register_sysctl_table - register a sysctl hierarchy
1473 * @table: the top-level table structure
1475 * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1476 * array. An entry with a ctl_name of 0 terminates the table.
1478 * The members of the &struct ctl_table structure are used as follows:
1480 * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1481 * must be unique within that level of sysctl
1483 * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1484 * enter a sysctl file
1486 * data - a pointer to data for use by proc_handler
1488 * maxlen - the maximum size in bytes of the data
1490 * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1492 * child - a pointer to the child sysctl table if this entry is a directory, or
1493 * %NULL.
1495 * proc_handler - the text handler routine (described below)
1497 * strategy - the strategy routine (described below)
1499 * de - for internal use by the sysctl routines
1501 * extra1, extra2 - extra pointers usable by the proc handler routines
1503 * Leaf nodes in the sysctl tree will be represented by a single file
1504 * under /proc; non-leaf nodes will be represented by directories.
1506 * sysctl(2) can automatically manage read and write requests through
1507 * the sysctl table. The data and maxlen fields of the ctl_table
1508 * struct enable minimal validation of the values being written to be
1509 * performed, and the mode field allows minimal authentication.
1511 * More sophisticated management can be enabled by the provision of a
1512 * strategy routine with the table entry. This will be called before
1513 * any automatic read or write of the data is performed.
1515 * The strategy routine may return
1517 * < 0 - Error occurred (error is passed to user process)
1519 * 0 - OK - proceed with automatic read or write.
1521 * > 0 - OK - read or write has been done by the strategy routine, so
1522 * return immediately.
1524 * There must be a proc_handler routine for any terminal nodes
1525 * mirrored under /proc/sys (non-terminals are handled by a built-in
1526 * directory handler). Several default handlers are available to
1527 * cover common cases -
1529 * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1530 * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(),
1531 * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1533 * It is the handler's job to read the input buffer from user memory
1534 * and process it. The handler should return 0 on success.
1536 * This routine returns %NULL on a failure to register, and a pointer
1537 * to the table header on success.
1539 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1541 struct ctl_table_header *tmp;
1542 tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1543 if (!tmp)
1544 return NULL;
1545 tmp->ctl_table = table;
1546 INIT_LIST_HEAD(&tmp->ctl_entry);
1547 tmp->used = 0;
1548 tmp->unregistering = NULL;
1549 sysctl_set_parent(NULL, table);
1550 spin_lock(&sysctl_lock);
1551 list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1552 spin_unlock(&sysctl_lock);
1553 return tmp;
1557 * unregister_sysctl_table - unregister a sysctl table hierarchy
1558 * @header: the header returned from register_sysctl_table
1560 * Unregisters the sysctl table and all children. proc entries may not
1561 * actually be removed until they are no longer used by anyone.
1563 void unregister_sysctl_table(struct ctl_table_header * header)
1565 might_sleep();
1566 spin_lock(&sysctl_lock);
1567 start_unregistering(header);
1568 spin_unlock(&sysctl_lock);
1569 kfree(header);
1572 #else /* !CONFIG_SYSCTL */
1573 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1575 return NULL;
1578 void unregister_sysctl_table(struct ctl_table_header * table)
1582 #endif /* CONFIG_SYSCTL */
1585 * /proc/sys support
1588 #ifdef CONFIG_PROC_SYSCTL
1590 static int _proc_do_string(void* data, int maxlen, int write,
1591 struct file *filp, void __user *buffer,
1592 size_t *lenp, loff_t *ppos)
1594 size_t len;
1595 char __user *p;
1596 char c;
1598 if (!data || !maxlen || !*lenp) {
1599 *lenp = 0;
1600 return 0;
1603 if (write) {
1604 len = 0;
1605 p = buffer;
1606 while (len < *lenp) {
1607 if (get_user(c, p++))
1608 return -EFAULT;
1609 if (c == 0 || c == '\n')
1610 break;
1611 len++;
1613 if (len >= maxlen)
1614 len = maxlen-1;
1615 if(copy_from_user(data, buffer, len))
1616 return -EFAULT;
1617 ((char *) data)[len] = 0;
1618 *ppos += *lenp;
1619 } else {
1620 len = strlen(data);
1621 if (len > maxlen)
1622 len = maxlen;
1624 if (*ppos > len) {
1625 *lenp = 0;
1626 return 0;
1629 data += *ppos;
1630 len -= *ppos;
1632 if (len > *lenp)
1633 len = *lenp;
1634 if (len)
1635 if(copy_to_user(buffer, data, len))
1636 return -EFAULT;
1637 if (len < *lenp) {
1638 if(put_user('\n', ((char __user *) buffer) + len))
1639 return -EFAULT;
1640 len++;
1642 *lenp = len;
1643 *ppos += len;
1645 return 0;
1649 * proc_dostring - read a string sysctl
1650 * @table: the sysctl table
1651 * @write: %TRUE if this is a write to the sysctl file
1652 * @filp: the file structure
1653 * @buffer: the user buffer
1654 * @lenp: the size of the user buffer
1655 * @ppos: file position
1657 * Reads/writes a string from/to the user buffer. If the kernel
1658 * buffer provided is not large enough to hold the string, the
1659 * string is truncated. The copied string is %NULL-terminated.
1660 * If the string is being read by the user process, it is copied
1661 * and a newline '\n' is added. It is truncated if the buffer is
1662 * not large enough.
1664 * Returns 0 on success.
1666 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1667 void __user *buffer, size_t *lenp, loff_t *ppos)
1669 return _proc_do_string(table->data, table->maxlen, write, filp,
1670 buffer, lenp, ppos);
1674 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1675 int *valp,
1676 int write, void *data)
1678 if (write) {
1679 *valp = *negp ? -*lvalp : *lvalp;
1680 } else {
1681 int val = *valp;
1682 if (val < 0) {
1683 *negp = -1;
1684 *lvalp = (unsigned long)-val;
1685 } else {
1686 *negp = 0;
1687 *lvalp = (unsigned long)val;
1690 return 0;
1693 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1694 int write, struct file *filp, void __user *buffer,
1695 size_t *lenp, loff_t *ppos,
1696 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1697 int write, void *data),
1698 void *data)
1700 #define TMPBUFLEN 21
1701 int *i, vleft, first=1, neg, val;
1702 unsigned long lval;
1703 size_t left, len;
1705 char buf[TMPBUFLEN], *p;
1706 char __user *s = buffer;
1708 if (!tbl_data || !table->maxlen || !*lenp ||
1709 (*ppos && !write)) {
1710 *lenp = 0;
1711 return 0;
1714 i = (int *) tbl_data;
1715 vleft = table->maxlen / sizeof(*i);
1716 left = *lenp;
1718 if (!conv)
1719 conv = do_proc_dointvec_conv;
1721 for (; left && vleft--; i++, first=0) {
1722 if (write) {
1723 while (left) {
1724 char c;
1725 if (get_user(c, s))
1726 return -EFAULT;
1727 if (!isspace(c))
1728 break;
1729 left--;
1730 s++;
1732 if (!left)
1733 break;
1734 neg = 0;
1735 len = left;
1736 if (len > sizeof(buf) - 1)
1737 len = sizeof(buf) - 1;
1738 if (copy_from_user(buf, s, len))
1739 return -EFAULT;
1740 buf[len] = 0;
1741 p = buf;
1742 if (*p == '-' && left > 1) {
1743 neg = 1;
1744 p++;
1746 if (*p < '0' || *p > '9')
1747 break;
1749 lval = simple_strtoul(p, &p, 0);
1751 len = p-buf;
1752 if ((len < left) && *p && !isspace(*p))
1753 break;
1754 if (neg)
1755 val = -val;
1756 s += len;
1757 left -= len;
1759 if (conv(&neg, &lval, i, 1, data))
1760 break;
1761 } else {
1762 p = buf;
1763 if (!first)
1764 *p++ = '\t';
1766 if (conv(&neg, &lval, i, 0, data))
1767 break;
1769 sprintf(p, "%s%lu", neg ? "-" : "", lval);
1770 len = strlen(buf);
1771 if (len > left)
1772 len = left;
1773 if(copy_to_user(s, buf, len))
1774 return -EFAULT;
1775 left -= len;
1776 s += len;
1780 if (!write && !first && left) {
1781 if(put_user('\n', s))
1782 return -EFAULT;
1783 left--, s++;
1785 if (write) {
1786 while (left) {
1787 char c;
1788 if (get_user(c, s++))
1789 return -EFAULT;
1790 if (!isspace(c))
1791 break;
1792 left--;
1795 if (write && first)
1796 return -EINVAL;
1797 *lenp -= left;
1798 *ppos += *lenp;
1799 return 0;
1800 #undef TMPBUFLEN
1803 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1804 void __user *buffer, size_t *lenp, loff_t *ppos,
1805 int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1806 int write, void *data),
1807 void *data)
1809 return __do_proc_dointvec(table->data, table, write, filp,
1810 buffer, lenp, ppos, conv, data);
1814 * proc_dointvec - read a vector of integers
1815 * @table: the sysctl table
1816 * @write: %TRUE if this is a write to the sysctl file
1817 * @filp: the file structure
1818 * @buffer: the user buffer
1819 * @lenp: the size of the user buffer
1820 * @ppos: file position
1822 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1823 * values from/to the user buffer, treated as an ASCII string.
1825 * Returns 0 on success.
1827 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1828 void __user *buffer, size_t *lenp, loff_t *ppos)
1830 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1831 NULL,NULL);
1834 #define OP_SET 0
1835 #define OP_AND 1
1836 #define OP_OR 2
1838 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1839 int *valp,
1840 int write, void *data)
1842 int op = *(int *)data;
1843 if (write) {
1844 int val = *negp ? -*lvalp : *lvalp;
1845 switch(op) {
1846 case OP_SET: *valp = val; break;
1847 case OP_AND: *valp &= val; break;
1848 case OP_OR: *valp |= val; break;
1850 } else {
1851 int val = *valp;
1852 if (val < 0) {
1853 *negp = -1;
1854 *lvalp = (unsigned long)-val;
1855 } else {
1856 *negp = 0;
1857 *lvalp = (unsigned long)val;
1860 return 0;
1864 * init may raise the set.
1867 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1868 void __user *buffer, size_t *lenp, loff_t *ppos)
1870 int op;
1872 if (write && !capable(CAP_SYS_MODULE)) {
1873 return -EPERM;
1876 op = is_init(current) ? OP_SET : OP_AND;
1877 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1878 do_proc_dointvec_bset_conv,&op);
1882 * Taint values can only be increased
1884 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1885 void __user *buffer, size_t *lenp, loff_t *ppos)
1887 int op;
1889 if (write && !capable(CAP_SYS_ADMIN))
1890 return -EPERM;
1892 op = OP_OR;
1893 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1894 do_proc_dointvec_bset_conv,&op);
1897 struct do_proc_dointvec_minmax_conv_param {
1898 int *min;
1899 int *max;
1902 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp,
1903 int *valp,
1904 int write, void *data)
1906 struct do_proc_dointvec_minmax_conv_param *param = data;
1907 if (write) {
1908 int val = *negp ? -*lvalp : *lvalp;
1909 if ((param->min && *param->min > val) ||
1910 (param->max && *param->max < val))
1911 return -EINVAL;
1912 *valp = val;
1913 } else {
1914 int val = *valp;
1915 if (val < 0) {
1916 *negp = -1;
1917 *lvalp = (unsigned long)-val;
1918 } else {
1919 *negp = 0;
1920 *lvalp = (unsigned long)val;
1923 return 0;
1927 * proc_dointvec_minmax - read a vector of integers with min/max values
1928 * @table: the sysctl table
1929 * @write: %TRUE if this is a write to the sysctl file
1930 * @filp: the file structure
1931 * @buffer: the user buffer
1932 * @lenp: the size of the user buffer
1933 * @ppos: file position
1935 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1936 * values from/to the user buffer, treated as an ASCII string.
1938 * This routine will ensure the values are within the range specified by
1939 * table->extra1 (min) and table->extra2 (max).
1941 * Returns 0 on success.
1943 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1944 void __user *buffer, size_t *lenp, loff_t *ppos)
1946 struct do_proc_dointvec_minmax_conv_param param = {
1947 .min = (int *) table->extra1,
1948 .max = (int *) table->extra2,
1950 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1951 do_proc_dointvec_minmax_conv, &param);
1954 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1955 struct file *filp,
1956 void __user *buffer,
1957 size_t *lenp, loff_t *ppos,
1958 unsigned long convmul,
1959 unsigned long convdiv)
1961 #define TMPBUFLEN 21
1962 unsigned long *i, *min, *max, val;
1963 int vleft, first=1, neg;
1964 size_t len, left;
1965 char buf[TMPBUFLEN], *p;
1966 char __user *s = buffer;
1968 if (!data || !table->maxlen || !*lenp ||
1969 (*ppos && !write)) {
1970 *lenp = 0;
1971 return 0;
1974 i = (unsigned long *) data;
1975 min = (unsigned long *) table->extra1;
1976 max = (unsigned long *) table->extra2;
1977 vleft = table->maxlen / sizeof(unsigned long);
1978 left = *lenp;
1980 for (; left && vleft--; i++, min++, max++, first=0) {
1981 if (write) {
1982 while (left) {
1983 char c;
1984 if (get_user(c, s))
1985 return -EFAULT;
1986 if (!isspace(c))
1987 break;
1988 left--;
1989 s++;
1991 if (!left)
1992 break;
1993 neg = 0;
1994 len = left;
1995 if (len > TMPBUFLEN-1)
1996 len = TMPBUFLEN-1;
1997 if (copy_from_user(buf, s, len))
1998 return -EFAULT;
1999 buf[len] = 0;
2000 p = buf;
2001 if (*p == '-' && left > 1) {
2002 neg = 1;
2003 p++;
2005 if (*p < '0' || *p > '9')
2006 break;
2007 val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2008 len = p-buf;
2009 if ((len < left) && *p && !isspace(*p))
2010 break;
2011 if (neg)
2012 val = -val;
2013 s += len;
2014 left -= len;
2016 if(neg)
2017 continue;
2018 if ((min && val < *min) || (max && val > *max))
2019 continue;
2020 *i = val;
2021 } else {
2022 p = buf;
2023 if (!first)
2024 *p++ = '\t';
2025 sprintf(p, "%lu", convdiv * (*i) / convmul);
2026 len = strlen(buf);
2027 if (len > left)
2028 len = left;
2029 if(copy_to_user(s, buf, len))
2030 return -EFAULT;
2031 left -= len;
2032 s += len;
2036 if (!write && !first && left) {
2037 if(put_user('\n', s))
2038 return -EFAULT;
2039 left--, s++;
2041 if (write) {
2042 while (left) {
2043 char c;
2044 if (get_user(c, s++))
2045 return -EFAULT;
2046 if (!isspace(c))
2047 break;
2048 left--;
2051 if (write && first)
2052 return -EINVAL;
2053 *lenp -= left;
2054 *ppos += *lenp;
2055 return 0;
2056 #undef TMPBUFLEN
2059 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2060 struct file *filp,
2061 void __user *buffer,
2062 size_t *lenp, loff_t *ppos,
2063 unsigned long convmul,
2064 unsigned long convdiv)
2066 return __do_proc_doulongvec_minmax(table->data, table, write,
2067 filp, buffer, lenp, ppos, convmul, convdiv);
2071 * proc_doulongvec_minmax - read a vector of long integers with min/max values
2072 * @table: the sysctl table
2073 * @write: %TRUE if this is a write to the sysctl file
2074 * @filp: the file structure
2075 * @buffer: the user buffer
2076 * @lenp: the size of the user buffer
2077 * @ppos: file position
2079 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2080 * values from/to the user buffer, treated as an ASCII string.
2082 * This routine will ensure the values are within the range specified by
2083 * table->extra1 (min) and table->extra2 (max).
2085 * Returns 0 on success.
2087 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2088 void __user *buffer, size_t *lenp, loff_t *ppos)
2090 return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2094 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2095 * @table: the sysctl table
2096 * @write: %TRUE if this is a write to the sysctl file
2097 * @filp: the file structure
2098 * @buffer: the user buffer
2099 * @lenp: the size of the user buffer
2100 * @ppos: file position
2102 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2103 * values from/to the user buffer, treated as an ASCII string. The values
2104 * are treated as milliseconds, and converted to jiffies when they are stored.
2106 * This routine will ensure the values are within the range specified by
2107 * table->extra1 (min) and table->extra2 (max).
2109 * Returns 0 on success.
2111 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2112 struct file *filp,
2113 void __user *buffer,
2114 size_t *lenp, loff_t *ppos)
2116 return do_proc_doulongvec_minmax(table, write, filp, buffer,
2117 lenp, ppos, HZ, 1000l);
2121 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2122 int *valp,
2123 int write, void *data)
2125 if (write) {
2126 if (*lvalp > LONG_MAX / HZ)
2127 return 1;
2128 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2129 } else {
2130 int val = *valp;
2131 unsigned long lval;
2132 if (val < 0) {
2133 *negp = -1;
2134 lval = (unsigned long)-val;
2135 } else {
2136 *negp = 0;
2137 lval = (unsigned long)val;
2139 *lvalp = lval / HZ;
2141 return 0;
2144 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2145 int *valp,
2146 int write, void *data)
2148 if (write) {
2149 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2150 return 1;
2151 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2152 } else {
2153 int val = *valp;
2154 unsigned long lval;
2155 if (val < 0) {
2156 *negp = -1;
2157 lval = (unsigned long)-val;
2158 } else {
2159 *negp = 0;
2160 lval = (unsigned long)val;
2162 *lvalp = jiffies_to_clock_t(lval);
2164 return 0;
2167 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2168 int *valp,
2169 int write, void *data)
2171 if (write) {
2172 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2173 } else {
2174 int val = *valp;
2175 unsigned long lval;
2176 if (val < 0) {
2177 *negp = -1;
2178 lval = (unsigned long)-val;
2179 } else {
2180 *negp = 0;
2181 lval = (unsigned long)val;
2183 *lvalp = jiffies_to_msecs(lval);
2185 return 0;
2189 * proc_dointvec_jiffies - read a vector of integers as seconds
2190 * @table: the sysctl table
2191 * @write: %TRUE if this is a write to the sysctl file
2192 * @filp: the file structure
2193 * @buffer: the user buffer
2194 * @lenp: the size of the user buffer
2195 * @ppos: file position
2197 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2198 * values from/to the user buffer, treated as an ASCII string.
2199 * The values read are assumed to be in seconds, and are converted into
2200 * jiffies.
2202 * Returns 0 on success.
2204 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2205 void __user *buffer, size_t *lenp, loff_t *ppos)
2207 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2208 do_proc_dointvec_jiffies_conv,NULL);
2212 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2213 * @table: the sysctl table
2214 * @write: %TRUE if this is a write to the sysctl file
2215 * @filp: the file structure
2216 * @buffer: the user buffer
2217 * @lenp: the size of the user buffer
2218 * @ppos: pointer to the file position
2220 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2221 * values from/to the user buffer, treated as an ASCII string.
2222 * The values read are assumed to be in 1/USER_HZ seconds, and
2223 * are converted into jiffies.
2225 * Returns 0 on success.
2227 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2228 void __user *buffer, size_t *lenp, loff_t *ppos)
2230 return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2231 do_proc_dointvec_userhz_jiffies_conv,NULL);
2235 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2236 * @table: the sysctl table
2237 * @write: %TRUE if this is a write to the sysctl file
2238 * @filp: the file structure
2239 * @buffer: the user buffer
2240 * @lenp: the size of the user buffer
2241 * @ppos: file position
2242 * @ppos: the current position in the file
2244 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2245 * values from/to the user buffer, treated as an ASCII string.
2246 * The values read are assumed to be in 1/1000 seconds, and
2247 * are converted into jiffies.
2249 * Returns 0 on success.
2251 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2252 void __user *buffer, size_t *lenp, loff_t *ppos)
2254 return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2255 do_proc_dointvec_ms_jiffies_conv, NULL);
2258 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2259 void __user *buffer, size_t *lenp, loff_t *ppos)
2261 struct pid *new_pid;
2262 pid_t tmp;
2263 int r;
2265 tmp = pid_nr(cad_pid);
2267 r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2268 lenp, ppos, NULL, NULL);
2269 if (r || !write)
2270 return r;
2272 new_pid = find_get_pid(tmp);
2273 if (!new_pid)
2274 return -ESRCH;
2276 put_pid(xchg(&cad_pid, new_pid));
2277 return 0;
2280 #else /* CONFIG_PROC_FS */
2282 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2283 void __user *buffer, size_t *lenp, loff_t *ppos)
2285 return -ENOSYS;
2288 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2289 void __user *buffer, size_t *lenp, loff_t *ppos)
2291 return -ENOSYS;
2294 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2295 void __user *buffer, size_t *lenp, loff_t *ppos)
2297 return -ENOSYS;
2300 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2301 void __user *buffer, size_t *lenp, loff_t *ppos)
2303 return -ENOSYS;
2306 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2307 void __user *buffer, size_t *lenp, loff_t *ppos)
2309 return -ENOSYS;
2312 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2313 void __user *buffer, size_t *lenp, loff_t *ppos)
2315 return -ENOSYS;
2318 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2319 void __user *buffer, size_t *lenp, loff_t *ppos)
2321 return -ENOSYS;
2324 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2325 void __user *buffer, size_t *lenp, loff_t *ppos)
2327 return -ENOSYS;
2330 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2331 struct file *filp,
2332 void __user *buffer,
2333 size_t *lenp, loff_t *ppos)
2335 return -ENOSYS;
2339 #endif /* CONFIG_PROC_FS */
2342 #ifdef CONFIG_SYSCTL_SYSCALL
2344 * General sysctl support routines
2347 /* The generic sysctl data routine (used if no strategy routine supplied) */
2348 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2349 void __user *oldval, size_t __user *oldlenp,
2350 void __user *newval, size_t newlen)
2352 size_t len;
2354 /* Get out of I don't have a variable */
2355 if (!table->data || !table->maxlen)
2356 return -ENOTDIR;
2358 if (oldval && oldlenp) {
2359 if (get_user(len, oldlenp))
2360 return -EFAULT;
2361 if (len) {
2362 if (len > table->maxlen)
2363 len = table->maxlen;
2364 if (copy_to_user(oldval, table->data, len))
2365 return -EFAULT;
2366 if (put_user(len, oldlenp))
2367 return -EFAULT;
2371 if (newval && newlen) {
2372 if (newlen > table->maxlen)
2373 newlen = table->maxlen;
2375 if (copy_from_user(table->data, newval, newlen))
2376 return -EFAULT;
2378 return 1;
2381 /* The generic string strategy routine: */
2382 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2383 void __user *oldval, size_t __user *oldlenp,
2384 void __user *newval, size_t newlen)
2386 if (!table->data || !table->maxlen)
2387 return -ENOTDIR;
2389 if (oldval && oldlenp) {
2390 size_t bufsize;
2391 if (get_user(bufsize, oldlenp))
2392 return -EFAULT;
2393 if (bufsize) {
2394 size_t len = strlen(table->data), copied;
2396 /* This shouldn't trigger for a well-formed sysctl */
2397 if (len > table->maxlen)
2398 len = table->maxlen;
2400 /* Copy up to a max of bufsize-1 bytes of the string */
2401 copied = (len >= bufsize) ? bufsize - 1 : len;
2403 if (copy_to_user(oldval, table->data, copied) ||
2404 put_user(0, (char __user *)(oldval + copied)))
2405 return -EFAULT;
2406 if (put_user(len, oldlenp))
2407 return -EFAULT;
2410 if (newval && newlen) {
2411 size_t len = newlen;
2412 if (len > table->maxlen)
2413 len = table->maxlen;
2414 if(copy_from_user(table->data, newval, len))
2415 return -EFAULT;
2416 if (len == table->maxlen)
2417 len--;
2418 ((char *) table->data)[len] = 0;
2420 return 1;
2424 * This function makes sure that all of the integers in the vector
2425 * are between the minimum and maximum values given in the arrays
2426 * table->extra1 and table->extra2, respectively.
2428 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2429 void __user *oldval, size_t __user *oldlenp,
2430 void __user *newval, size_t newlen)
2433 if (newval && newlen) {
2434 int __user *vec = (int __user *) newval;
2435 int *min = (int *) table->extra1;
2436 int *max = (int *) table->extra2;
2437 size_t length;
2438 int i;
2440 if (newlen % sizeof(int) != 0)
2441 return -EINVAL;
2443 if (!table->extra1 && !table->extra2)
2444 return 0;
2446 if (newlen > table->maxlen)
2447 newlen = table->maxlen;
2448 length = newlen / sizeof(int);
2450 for (i = 0; i < length; i++) {
2451 int value;
2452 if (get_user(value, vec + i))
2453 return -EFAULT;
2454 if (min && value < min[i])
2455 return -EINVAL;
2456 if (max && value > max[i])
2457 return -EINVAL;
2460 return 0;
2463 /* Strategy function to convert jiffies to seconds */
2464 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2465 void __user *oldval, size_t __user *oldlenp,
2466 void __user *newval, size_t newlen)
2468 if (oldval && oldlenp) {
2469 size_t olen;
2471 if (get_user(olen, oldlenp))
2472 return -EFAULT;
2473 if (olen) {
2474 int val;
2476 if (olen < sizeof(int))
2477 return -EINVAL;
2479 val = *(int *)(table->data) / HZ;
2480 if (put_user(val, (int __user *)oldval))
2481 return -EFAULT;
2482 if (put_user(sizeof(int), oldlenp))
2483 return -EFAULT;
2486 if (newval && newlen) {
2487 int new;
2488 if (newlen != sizeof(int))
2489 return -EINVAL;
2490 if (get_user(new, (int __user *)newval))
2491 return -EFAULT;
2492 *(int *)(table->data) = new*HZ;
2494 return 1;
2497 /* Strategy function to convert jiffies to seconds */
2498 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2499 void __user *oldval, size_t __user *oldlenp,
2500 void __user *newval, size_t newlen)
2502 if (oldval && oldlenp) {
2503 size_t olen;
2505 if (get_user(olen, oldlenp))
2506 return -EFAULT;
2507 if (olen) {
2508 int val;
2510 if (olen < sizeof(int))
2511 return -EINVAL;
2513 val = jiffies_to_msecs(*(int *)(table->data));
2514 if (put_user(val, (int __user *)oldval))
2515 return -EFAULT;
2516 if (put_user(sizeof(int), oldlenp))
2517 return -EFAULT;
2520 if (newval && newlen) {
2521 int new;
2522 if (newlen != sizeof(int))
2523 return -EINVAL;
2524 if (get_user(new, (int __user *)newval))
2525 return -EFAULT;
2526 *(int *)(table->data) = msecs_to_jiffies(new);
2528 return 1;
2533 #else /* CONFIG_SYSCTL_SYSCALL */
2536 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2538 static int msg_count;
2539 struct __sysctl_args tmp;
2540 int name[CTL_MAXNAME];
2541 int i;
2543 /* Read in the sysctl name for better debug message logging */
2544 if (copy_from_user(&tmp, args, sizeof(tmp)))
2545 return -EFAULT;
2546 if (tmp.nlen <= 0 || tmp.nlen >= CTL_MAXNAME)
2547 return -ENOTDIR;
2548 for (i = 0; i < tmp.nlen; i++)
2549 if (get_user(name[i], tmp.name + i))
2550 return -EFAULT;
2552 /* Ignore accesses to kernel.version */
2553 if ((tmp.nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2554 goto out;
2556 if (msg_count < 5) {
2557 msg_count++;
2558 printk(KERN_INFO
2559 "warning: process `%s' used the removed sysctl "
2560 "system call with ", current->comm);
2561 for (i = 0; i < tmp.nlen; i++)
2562 printk("%d.", name[i]);
2563 printk("\n");
2565 out:
2566 return -ENOSYS;
2569 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2570 void __user *oldval, size_t __user *oldlenp,
2571 void __user *newval, size_t newlen)
2573 return -ENOSYS;
2576 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2577 void __user *oldval, size_t __user *oldlenp,
2578 void __user *newval, size_t newlen)
2580 return -ENOSYS;
2583 int sysctl_intvec(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_jiffies(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_ms_jiffies(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 #endif /* CONFIG_SYSCTL_SYSCALL */
2607 * No sense putting this after each symbol definition, twice,
2608 * exception granted :-)
2610 EXPORT_SYMBOL(proc_dointvec);
2611 EXPORT_SYMBOL(proc_dointvec_jiffies);
2612 EXPORT_SYMBOL(proc_dointvec_minmax);
2613 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2614 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2615 EXPORT_SYMBOL(proc_dostring);
2616 EXPORT_SYMBOL(proc_doulongvec_minmax);
2617 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2618 EXPORT_SYMBOL(register_sysctl_table);
2619 EXPORT_SYMBOL(sysctl_intvec);
2620 EXPORT_SYMBOL(sysctl_jiffies);
2621 EXPORT_SYMBOL(sysctl_ms_jiffies);
2622 EXPORT_SYMBOL(sysctl_string);
2623 EXPORT_SYMBOL(sysctl_data);
2624 EXPORT_SYMBOL(unregister_sysctl_table);