]> pilppa.org Git - linux-2.6-omap-h63xx.git/blob - kernel/sysctl.c
sysctl: deprecate sys_sysctl in a user space visible fashion.
[linux-2.6-omap-h63xx.git] / kernel / sysctl.c
1 /*
2  * sysctl.c: General linux system control interface
3  *
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
19  */
20
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>
49
50 #include <asm/uaccess.h>
51 #include <asm/processor.h>
52
53 #ifdef CONFIG_X86
54 #include <asm/nmi.h>
55 #include <asm/stacktrace.h>
56 #endif
57
58 static int deprecated_sysctl_warning(struct __sysctl_args *args);
59
60 #if defined(CONFIG_SYSCTL)
61
62 /* External variables not in a header file. */
63 extern int C_A_D;
64 extern int print_fatal_signals;
65 extern int sysctl_overcommit_memory;
66 extern int sysctl_overcommit_ratio;
67 extern int sysctl_panic_on_oom;
68 extern int sysctl_oom_kill_allocating_task;
69 extern int max_threads;
70 extern int core_uses_pid;
71 extern int suid_dumpable;
72 extern char core_pattern[];
73 extern int pid_max;
74 extern int min_free_kbytes;
75 extern int printk_ratelimit_jiffies;
76 extern int printk_ratelimit_burst;
77 extern int pid_max_min, pid_max_max;
78 extern int sysctl_drop_caches;
79 extern int percpu_pagelist_fraction;
80 extern int compat_log;
81 extern int maps_protect;
82 extern int sysctl_stat_interval;
83 extern int audit_argv_kb;
84
85 /* Constants used for minimum and  maximum */
86 #ifdef CONFIG_DETECT_SOFTLOCKUP
87 static int one = 1;
88 static int sixty = 60;
89 #endif
90
91 #ifdef CONFIG_MMU
92 static int two = 2;
93 #endif
94
95 static int zero;
96 static int one_hundred = 100;
97
98 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
99 static int maxolduid = 65535;
100 static int minolduid;
101 static int min_percpu_pagelist_fract = 8;
102
103 static int ngroups_max = NGROUPS_MAX;
104
105 #ifdef CONFIG_KMOD
106 extern char modprobe_path[];
107 #endif
108 #ifdef CONFIG_CHR_DEV_SG
109 extern int sg_big_buff;
110 #endif
111
112 #ifdef __sparc__
113 extern char reboot_command [];
114 extern int stop_a_enabled;
115 extern int scons_pwroff;
116 #endif
117
118 #ifdef __hppa__
119 extern int pwrsw_enabled;
120 extern int unaligned_enabled;
121 #endif
122
123 #ifdef CONFIG_S390
124 #ifdef CONFIG_MATHEMU
125 extern int sysctl_ieee_emulation_warnings;
126 #endif
127 extern int sysctl_userprocess_debug;
128 extern int spin_retry;
129 #endif
130
131 extern int sysctl_hz_timer;
132
133 #ifdef CONFIG_BSD_PROCESS_ACCT
134 extern int acct_parm[];
135 #endif
136
137 #ifdef CONFIG_IA64
138 extern int no_unaligned_warning;
139 #endif
140
141 #ifdef CONFIG_RT_MUTEXES
142 extern int max_lock_depth;
143 #endif
144
145 #ifdef CONFIG_SYSCTL_SYSCALL
146 static int parse_table(int __user *, int, void __user *, size_t __user *,
147                 void __user *, size_t, struct ctl_table *);
148 #endif
149
150
151 #ifdef CONFIG_PROC_SYSCTL
152 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
153                   void __user *buffer, size_t *lenp, loff_t *ppos);
154 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
155                                void __user *buffer, size_t *lenp, loff_t *ppos);
156 #endif
157
158 static struct ctl_table root_table[];
159 static struct ctl_table_header root_table_header =
160         { root_table, LIST_HEAD_INIT(root_table_header.ctl_entry) };
161
162 static struct ctl_table kern_table[];
163 static struct ctl_table vm_table[];
164 static struct ctl_table fs_table[];
165 static struct ctl_table debug_table[];
166 static struct ctl_table dev_table[];
167 extern struct ctl_table random_table[];
168 #ifdef CONFIG_INOTIFY_USER
169 extern struct ctl_table inotify_table[];
170 #endif
171
172 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
173 int sysctl_legacy_va_layout;
174 #endif
175
176 extern int prove_locking;
177 extern int lock_stat;
178
179 /* The default sysctl tables: */
180
181 static struct ctl_table root_table[] = {
182         {
183                 .ctl_name       = CTL_KERN,
184                 .procname       = "kernel",
185                 .mode           = 0555,
186                 .child          = kern_table,
187         },
188         {
189                 .ctl_name       = CTL_VM,
190                 .procname       = "vm",
191                 .mode           = 0555,
192                 .child          = vm_table,
193         },
194 #ifdef CONFIG_NET
195         {
196                 .ctl_name       = CTL_NET,
197                 .procname       = "net",
198                 .mode           = 0555,
199                 .child          = net_table,
200         },
201 #endif
202         {
203                 .ctl_name       = CTL_FS,
204                 .procname       = "fs",
205                 .mode           = 0555,
206                 .child          = fs_table,
207         },
208         {
209                 .ctl_name       = CTL_DEBUG,
210                 .procname       = "debug",
211                 .mode           = 0555,
212                 .child          = debug_table,
213         },
214         {
215                 .ctl_name       = CTL_DEV,
216                 .procname       = "dev",
217                 .mode           = 0555,
218                 .child          = dev_table,
219         },
220 /*
221  * NOTE: do not add new entries to this table unless you have read
222  * Documentation/sysctl/ctl_unnumbered.txt
223  */
224         { .ctl_name = 0 }
225 };
226
227 #ifdef CONFIG_SCHED_DEBUG
228 static unsigned long min_sched_granularity_ns = 100000;         /* 100 usecs */
229 static unsigned long max_sched_granularity_ns = 1000000000;     /* 1 second */
230 static unsigned long min_wakeup_granularity_ns;                 /* 0 usecs */
231 static unsigned long max_wakeup_granularity_ns = 1000000000;    /* 1 second */
232 #endif
233
234 static struct ctl_table kern_table[] = {
235 #ifdef CONFIG_SCHED_DEBUG
236         {
237                 .ctl_name       = CTL_UNNUMBERED,
238                 .procname       = "sched_nr_latency",
239                 .data           = &sysctl_sched_nr_latency,
240                 .maxlen         = sizeof(unsigned int),
241                 .mode           = 0644,
242                 .proc_handler   = &proc_dointvec,
243         },
244         {
245                 .ctl_name       = CTL_UNNUMBERED,
246                 .procname       = "sched_latency_ns",
247                 .data           = &sysctl_sched_latency,
248                 .maxlen         = sizeof(unsigned int),
249                 .mode           = 0644,
250                 .proc_handler   = &proc_dointvec_minmax,
251                 .strategy       = &sysctl_intvec,
252                 .extra1         = &min_sched_granularity_ns,
253                 .extra2         = &max_sched_granularity_ns,
254         },
255         {
256                 .ctl_name       = CTL_UNNUMBERED,
257                 .procname       = "sched_wakeup_granularity_ns",
258                 .data           = &sysctl_sched_wakeup_granularity,
259                 .maxlen         = sizeof(unsigned int),
260                 .mode           = 0644,
261                 .proc_handler   = &proc_dointvec_minmax,
262                 .strategy       = &sysctl_intvec,
263                 .extra1         = &min_wakeup_granularity_ns,
264                 .extra2         = &max_wakeup_granularity_ns,
265         },
266         {
267                 .ctl_name       = CTL_UNNUMBERED,
268                 .procname       = "sched_batch_wakeup_granularity_ns",
269                 .data           = &sysctl_sched_batch_wakeup_granularity,
270                 .maxlen         = sizeof(unsigned int),
271                 .mode           = 0644,
272                 .proc_handler   = &proc_dointvec_minmax,
273                 .strategy       = &sysctl_intvec,
274                 .extra1         = &min_wakeup_granularity_ns,
275                 .extra2         = &max_wakeup_granularity_ns,
276         },
277         {
278                 .ctl_name       = CTL_UNNUMBERED,
279                 .procname       = "sched_child_runs_first",
280                 .data           = &sysctl_sched_child_runs_first,
281                 .maxlen         = sizeof(unsigned int),
282                 .mode           = 0644,
283                 .proc_handler   = &proc_dointvec,
284         },
285         {
286                 .ctl_name       = CTL_UNNUMBERED,
287                 .procname       = "sched_features",
288                 .data           = &sysctl_sched_features,
289                 .maxlen         = sizeof(unsigned int),
290                 .mode           = 0644,
291                 .proc_handler   = &proc_dointvec,
292         },
293         {
294                 .ctl_name       = CTL_UNNUMBERED,
295                 .procname       = "sched_migration_cost",
296                 .data           = &sysctl_sched_migration_cost,
297                 .maxlen         = sizeof(unsigned int),
298                 .mode           = 0644,
299                 .proc_handler   = &proc_dointvec,
300         },
301 #endif
302         {
303                 .ctl_name       = CTL_UNNUMBERED,
304                 .procname       = "sched_compat_yield",
305                 .data           = &sysctl_sched_compat_yield,
306                 .maxlen         = sizeof(unsigned int),
307                 .mode           = 0644,
308                 .proc_handler   = &proc_dointvec,
309         },
310 #ifdef CONFIG_PROVE_LOCKING
311         {
312                 .ctl_name       = CTL_UNNUMBERED,
313                 .procname       = "prove_locking",
314                 .data           = &prove_locking,
315                 .maxlen         = sizeof(int),
316                 .mode           = 0644,
317                 .proc_handler   = &proc_dointvec,
318         },
319 #endif
320 #ifdef CONFIG_LOCK_STAT
321         {
322                 .ctl_name       = CTL_UNNUMBERED,
323                 .procname       = "lock_stat",
324                 .data           = &lock_stat,
325                 .maxlen         = sizeof(int),
326                 .mode           = 0644,
327                 .proc_handler   = &proc_dointvec,
328         },
329 #endif
330         {
331                 .ctl_name       = KERN_PANIC,
332                 .procname       = "panic",
333                 .data           = &panic_timeout,
334                 .maxlen         = sizeof(int),
335                 .mode           = 0644,
336                 .proc_handler   = &proc_dointvec,
337         },
338         {
339                 .ctl_name       = KERN_CORE_USES_PID,
340                 .procname       = "core_uses_pid",
341                 .data           = &core_uses_pid,
342                 .maxlen         = sizeof(int),
343                 .mode           = 0644,
344                 .proc_handler   = &proc_dointvec,
345         },
346 #ifdef CONFIG_AUDITSYSCALL
347         {
348                 .ctl_name       = CTL_UNNUMBERED,
349                 .procname       = "audit_argv_kb",
350                 .data           = &audit_argv_kb,
351                 .maxlen         = sizeof(int),
352                 .mode           = 0644,
353                 .proc_handler   = &proc_dointvec,
354         },
355 #endif
356         {
357                 .ctl_name       = KERN_CORE_PATTERN,
358                 .procname       = "core_pattern",
359                 .data           = core_pattern,
360                 .maxlen         = CORENAME_MAX_SIZE,
361                 .mode           = 0644,
362                 .proc_handler   = &proc_dostring,
363                 .strategy       = &sysctl_string,
364         },
365 #ifdef CONFIG_PROC_SYSCTL
366         {
367                 .procname       = "tainted",
368                 .data           = &tainted,
369                 .maxlen         = sizeof(int),
370                 .mode           = 0644,
371                 .proc_handler   = &proc_dointvec_taint,
372         },
373 #endif
374         {
375                 .procname       = "cap-bound",
376                 .data           = &cap_bset,
377                 .maxlen         = sizeof(kernel_cap_t),
378                 .mode           = 0600,
379                 .proc_handler   = &proc_dointvec_bset,
380         },
381 #ifdef CONFIG_BLK_DEV_INITRD
382         {
383                 .ctl_name       = KERN_REALROOTDEV,
384                 .procname       = "real-root-dev",
385                 .data           = &real_root_dev,
386                 .maxlen         = sizeof(int),
387                 .mode           = 0644,
388                 .proc_handler   = &proc_dointvec,
389         },
390 #endif
391         {
392                 .ctl_name       = CTL_UNNUMBERED,
393                 .procname       = "print-fatal-signals",
394                 .data           = &print_fatal_signals,
395                 .maxlen         = sizeof(int),
396                 .mode           = 0644,
397                 .proc_handler   = &proc_dointvec,
398         },
399 #ifdef __sparc__
400         {
401                 .ctl_name       = KERN_SPARC_REBOOT,
402                 .procname       = "reboot-cmd",
403                 .data           = reboot_command,
404                 .maxlen         = 256,
405                 .mode           = 0644,
406                 .proc_handler   = &proc_dostring,
407                 .strategy       = &sysctl_string,
408         },
409         {
410                 .ctl_name       = KERN_SPARC_STOP_A,
411                 .procname       = "stop-a",
412                 .data           = &stop_a_enabled,
413                 .maxlen         = sizeof (int),
414                 .mode           = 0644,
415                 .proc_handler   = &proc_dointvec,
416         },
417         {
418                 .ctl_name       = KERN_SPARC_SCONS_PWROFF,
419                 .procname       = "scons-poweroff",
420                 .data           = &scons_pwroff,
421                 .maxlen         = sizeof (int),
422                 .mode           = 0644,
423                 .proc_handler   = &proc_dointvec,
424         },
425 #endif
426 #ifdef __hppa__
427         {
428                 .ctl_name       = KERN_HPPA_PWRSW,
429                 .procname       = "soft-power",
430                 .data           = &pwrsw_enabled,
431                 .maxlen         = sizeof (int),
432                 .mode           = 0644,
433                 .proc_handler   = &proc_dointvec,
434         },
435         {
436                 .ctl_name       = KERN_HPPA_UNALIGNED,
437                 .procname       = "unaligned-trap",
438                 .data           = &unaligned_enabled,
439                 .maxlen         = sizeof (int),
440                 .mode           = 0644,
441                 .proc_handler   = &proc_dointvec,
442         },
443 #endif
444         {
445                 .ctl_name       = KERN_CTLALTDEL,
446                 .procname       = "ctrl-alt-del",
447                 .data           = &C_A_D,
448                 .maxlen         = sizeof(int),
449                 .mode           = 0644,
450                 .proc_handler   = &proc_dointvec,
451         },
452         {
453                 .ctl_name       = KERN_PRINTK,
454                 .procname       = "printk",
455                 .data           = &console_loglevel,
456                 .maxlen         = 4*sizeof(int),
457                 .mode           = 0644,
458                 .proc_handler   = &proc_dointvec,
459         },
460 #ifdef CONFIG_KMOD
461         {
462                 .ctl_name       = KERN_MODPROBE,
463                 .procname       = "modprobe",
464                 .data           = &modprobe_path,
465                 .maxlen         = KMOD_PATH_LEN,
466                 .mode           = 0644,
467                 .proc_handler   = &proc_dostring,
468                 .strategy       = &sysctl_string,
469         },
470 #endif
471 #if defined(CONFIG_HOTPLUG) && defined(CONFIG_NET)
472         {
473                 .ctl_name       = KERN_HOTPLUG,
474                 .procname       = "hotplug",
475                 .data           = &uevent_helper,
476                 .maxlen         = UEVENT_HELPER_PATH_LEN,
477                 .mode           = 0644,
478                 .proc_handler   = &proc_dostring,
479                 .strategy       = &sysctl_string,
480         },
481 #endif
482 #ifdef CONFIG_CHR_DEV_SG
483         {
484                 .ctl_name       = KERN_SG_BIG_BUFF,
485                 .procname       = "sg-big-buff",
486                 .data           = &sg_big_buff,
487                 .maxlen         = sizeof (int),
488                 .mode           = 0444,
489                 .proc_handler   = &proc_dointvec,
490         },
491 #endif
492 #ifdef CONFIG_BSD_PROCESS_ACCT
493         {
494                 .ctl_name       = KERN_ACCT,
495                 .procname       = "acct",
496                 .data           = &acct_parm,
497                 .maxlen         = 3*sizeof(int),
498                 .mode           = 0644,
499                 .proc_handler   = &proc_dointvec,
500         },
501 #endif
502 #ifdef CONFIG_MAGIC_SYSRQ
503         {
504                 .ctl_name       = KERN_SYSRQ,
505                 .procname       = "sysrq",
506                 .data           = &__sysrq_enabled,
507                 .maxlen         = sizeof (int),
508                 .mode           = 0644,
509                 .proc_handler   = &proc_dointvec,
510         },
511 #endif
512 #ifdef CONFIG_PROC_SYSCTL
513         {
514                 .procname       = "cad_pid",
515                 .data           = NULL,
516                 .maxlen         = sizeof (int),
517                 .mode           = 0600,
518                 .proc_handler   = &proc_do_cad_pid,
519         },
520 #endif
521         {
522                 .ctl_name       = KERN_MAX_THREADS,
523                 .procname       = "threads-max",
524                 .data           = &max_threads,
525                 .maxlen         = sizeof(int),
526                 .mode           = 0644,
527                 .proc_handler   = &proc_dointvec,
528         },
529         {
530                 .ctl_name       = KERN_RANDOM,
531                 .procname       = "random",
532                 .mode           = 0555,
533                 .child          = random_table,
534         },
535         {
536                 .ctl_name       = KERN_OVERFLOWUID,
537                 .procname       = "overflowuid",
538                 .data           = &overflowuid,
539                 .maxlen         = sizeof(int),
540                 .mode           = 0644,
541                 .proc_handler   = &proc_dointvec_minmax,
542                 .strategy       = &sysctl_intvec,
543                 .extra1         = &minolduid,
544                 .extra2         = &maxolduid,
545         },
546         {
547                 .ctl_name       = KERN_OVERFLOWGID,
548                 .procname       = "overflowgid",
549                 .data           = &overflowgid,
550                 .maxlen         = sizeof(int),
551                 .mode           = 0644,
552                 .proc_handler   = &proc_dointvec_minmax,
553                 .strategy       = &sysctl_intvec,
554                 .extra1         = &minolduid,
555                 .extra2         = &maxolduid,
556         },
557 #ifdef CONFIG_S390
558 #ifdef CONFIG_MATHEMU
559         {
560                 .ctl_name       = KERN_IEEE_EMULATION_WARNINGS,
561                 .procname       = "ieee_emulation_warnings",
562                 .data           = &sysctl_ieee_emulation_warnings,
563                 .maxlen         = sizeof(int),
564                 .mode           = 0644,
565                 .proc_handler   = &proc_dointvec,
566         },
567 #endif
568 #ifdef CONFIG_NO_IDLE_HZ
569         {
570                 .ctl_name       = KERN_HZ_TIMER,
571                 .procname       = "hz_timer",
572                 .data           = &sysctl_hz_timer,
573                 .maxlen         = sizeof(int),
574                 .mode           = 0644,
575                 .proc_handler   = &proc_dointvec,
576         },
577 #endif
578         {
579                 .ctl_name       = KERN_S390_USER_DEBUG_LOGGING,
580                 .procname       = "userprocess_debug",
581                 .data           = &sysctl_userprocess_debug,
582                 .maxlen         = sizeof(int),
583                 .mode           = 0644,
584                 .proc_handler   = &proc_dointvec,
585         },
586 #endif
587         {
588                 .ctl_name       = KERN_PIDMAX,
589                 .procname       = "pid_max",
590                 .data           = &pid_max,
591                 .maxlen         = sizeof (int),
592                 .mode           = 0644,
593                 .proc_handler   = &proc_dointvec_minmax,
594                 .strategy       = sysctl_intvec,
595                 .extra1         = &pid_max_min,
596                 .extra2         = &pid_max_max,
597         },
598         {
599                 .ctl_name       = KERN_PANIC_ON_OOPS,
600                 .procname       = "panic_on_oops",
601                 .data           = &panic_on_oops,
602                 .maxlen         = sizeof(int),
603                 .mode           = 0644,
604                 .proc_handler   = &proc_dointvec,
605         },
606         {
607                 .ctl_name       = KERN_PRINTK_RATELIMIT,
608                 .procname       = "printk_ratelimit",
609                 .data           = &printk_ratelimit_jiffies,
610                 .maxlen         = sizeof(int),
611                 .mode           = 0644,
612                 .proc_handler   = &proc_dointvec_jiffies,
613                 .strategy       = &sysctl_jiffies,
614         },
615         {
616                 .ctl_name       = KERN_PRINTK_RATELIMIT_BURST,
617                 .procname       = "printk_ratelimit_burst",
618                 .data           = &printk_ratelimit_burst,
619                 .maxlen         = sizeof(int),
620                 .mode           = 0644,
621                 .proc_handler   = &proc_dointvec,
622         },
623         {
624                 .ctl_name       = KERN_NGROUPS_MAX,
625                 .procname       = "ngroups_max",
626                 .data           = &ngroups_max,
627                 .maxlen         = sizeof (int),
628                 .mode           = 0444,
629                 .proc_handler   = &proc_dointvec,
630         },
631 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
632         {
633                 .ctl_name       = KERN_UNKNOWN_NMI_PANIC,
634                 .procname       = "unknown_nmi_panic",
635                 .data           = &unknown_nmi_panic,
636                 .maxlen         = sizeof (int),
637                 .mode           = 0644,
638                 .proc_handler   = &proc_dointvec,
639         },
640         {
641                 .procname       = "nmi_watchdog",
642                 .data           = &nmi_watchdog_enabled,
643                 .maxlen         = sizeof (int),
644                 .mode           = 0644,
645                 .proc_handler   = &proc_nmi_enabled,
646         },
647 #endif
648 #if defined(CONFIG_X86)
649         {
650                 .ctl_name       = KERN_PANIC_ON_NMI,
651                 .procname       = "panic_on_unrecovered_nmi",
652                 .data           = &panic_on_unrecovered_nmi,
653                 .maxlen         = sizeof(int),
654                 .mode           = 0644,
655                 .proc_handler   = &proc_dointvec,
656         },
657         {
658                 .ctl_name       = KERN_BOOTLOADER_TYPE,
659                 .procname       = "bootloader_type",
660                 .data           = &bootloader_type,
661                 .maxlen         = sizeof (int),
662                 .mode           = 0444,
663                 .proc_handler   = &proc_dointvec,
664         },
665         {
666                 .ctl_name       = CTL_UNNUMBERED,
667                 .procname       = "kstack_depth_to_print",
668                 .data           = &kstack_depth_to_print,
669                 .maxlen         = sizeof(int),
670                 .mode           = 0644,
671                 .proc_handler   = &proc_dointvec,
672         },
673 #endif
674 #if defined(CONFIG_MMU)
675         {
676                 .ctl_name       = KERN_RANDOMIZE,
677                 .procname       = "randomize_va_space",
678                 .data           = &randomize_va_space,
679                 .maxlen         = sizeof(int),
680                 .mode           = 0644,
681                 .proc_handler   = &proc_dointvec,
682         },
683 #endif
684 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
685         {
686                 .ctl_name       = KERN_SPIN_RETRY,
687                 .procname       = "spin_retry",
688                 .data           = &spin_retry,
689                 .maxlen         = sizeof (int),
690                 .mode           = 0644,
691                 .proc_handler   = &proc_dointvec,
692         },
693 #endif
694 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
695         {
696                 .procname       = "acpi_video_flags",
697                 .data           = &acpi_realmode_flags,
698                 .maxlen         = sizeof (unsigned long),
699                 .mode           = 0644,
700                 .proc_handler   = &proc_doulongvec_minmax,
701         },
702 #endif
703 #ifdef CONFIG_IA64
704         {
705                 .ctl_name       = KERN_IA64_UNALIGNED,
706                 .procname       = "ignore-unaligned-usertrap",
707                 .data           = &no_unaligned_warning,
708                 .maxlen         = sizeof (int),
709                 .mode           = 0644,
710                 .proc_handler   = &proc_dointvec,
711         },
712 #endif
713 #ifdef CONFIG_DETECT_SOFTLOCKUP
714         {
715                 .ctl_name       = CTL_UNNUMBERED,
716                 .procname       = "softlockup_thresh",
717                 .data           = &softlockup_thresh,
718                 .maxlen         = sizeof(int),
719                 .mode           = 0644,
720                 .proc_handler   = &proc_dointvec_minmax,
721                 .strategy       = &sysctl_intvec,
722                 .extra1         = &one,
723                 .extra2         = &sixty,
724         },
725 #endif
726 #ifdef CONFIG_COMPAT
727         {
728                 .ctl_name       = KERN_COMPAT_LOG,
729                 .procname       = "compat-log",
730                 .data           = &compat_log,
731                 .maxlen         = sizeof (int),
732                 .mode           = 0644,
733                 .proc_handler   = &proc_dointvec,
734         },
735 #endif
736 #ifdef CONFIG_RT_MUTEXES
737         {
738                 .ctl_name       = KERN_MAX_LOCK_DEPTH,
739                 .procname       = "max_lock_depth",
740                 .data           = &max_lock_depth,
741                 .maxlen         = sizeof(int),
742                 .mode           = 0644,
743                 .proc_handler   = &proc_dointvec,
744         },
745 #endif
746 #ifdef CONFIG_PROC_FS
747         {
748                 .ctl_name       = CTL_UNNUMBERED,
749                 .procname       = "maps_protect",
750                 .data           = &maps_protect,
751                 .maxlen         = sizeof(int),
752                 .mode           = 0644,
753                 .proc_handler   = &proc_dointvec,
754         },
755 #endif
756         {
757                 .ctl_name       = CTL_UNNUMBERED,
758                 .procname       = "poweroff_cmd",
759                 .data           = &poweroff_cmd,
760                 .maxlen         = POWEROFF_CMD_PATH_LEN,
761                 .mode           = 0644,
762                 .proc_handler   = &proc_dostring,
763                 .strategy       = &sysctl_string,
764         },
765 /*
766  * NOTE: do not add new entries to this table unless you have read
767  * Documentation/sysctl/ctl_unnumbered.txt
768  */
769         { .ctl_name = 0 }
770 };
771
772 static struct ctl_table vm_table[] = {
773         {
774                 .ctl_name       = VM_OVERCOMMIT_MEMORY,
775                 .procname       = "overcommit_memory",
776                 .data           = &sysctl_overcommit_memory,
777                 .maxlen         = sizeof(sysctl_overcommit_memory),
778                 .mode           = 0644,
779                 .proc_handler   = &proc_dointvec,
780         },
781         {
782                 .ctl_name       = VM_PANIC_ON_OOM,
783                 .procname       = "panic_on_oom",
784                 .data           = &sysctl_panic_on_oom,
785                 .maxlen         = sizeof(sysctl_panic_on_oom),
786                 .mode           = 0644,
787                 .proc_handler   = &proc_dointvec,
788         },
789         {
790                 .ctl_name       = CTL_UNNUMBERED,
791                 .procname       = "oom_kill_allocating_task",
792                 .data           = &sysctl_oom_kill_allocating_task,
793                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
794                 .mode           = 0644,
795                 .proc_handler   = &proc_dointvec,
796         },
797         {
798                 .ctl_name       = VM_OVERCOMMIT_RATIO,
799                 .procname       = "overcommit_ratio",
800                 .data           = &sysctl_overcommit_ratio,
801                 .maxlen         = sizeof(sysctl_overcommit_ratio),
802                 .mode           = 0644,
803                 .proc_handler   = &proc_dointvec,
804         },
805         {
806                 .ctl_name       = VM_PAGE_CLUSTER,
807                 .procname       = "page-cluster", 
808                 .data           = &page_cluster,
809                 .maxlen         = sizeof(int),
810                 .mode           = 0644,
811                 .proc_handler   = &proc_dointvec,
812         },
813         {
814                 .ctl_name       = VM_DIRTY_BACKGROUND,
815                 .procname       = "dirty_background_ratio",
816                 .data           = &dirty_background_ratio,
817                 .maxlen         = sizeof(dirty_background_ratio),
818                 .mode           = 0644,
819                 .proc_handler   = &proc_dointvec_minmax,
820                 .strategy       = &sysctl_intvec,
821                 .extra1         = &zero,
822                 .extra2         = &one_hundred,
823         },
824         {
825                 .ctl_name       = VM_DIRTY_RATIO,
826                 .procname       = "dirty_ratio",
827                 .data           = &vm_dirty_ratio,
828                 .maxlen         = sizeof(vm_dirty_ratio),
829                 .mode           = 0644,
830                 .proc_handler   = &dirty_ratio_handler,
831                 .strategy       = &sysctl_intvec,
832                 .extra1         = &zero,
833                 .extra2         = &one_hundred,
834         },
835         {
836                 .procname       = "dirty_writeback_centisecs",
837                 .data           = &dirty_writeback_interval,
838                 .maxlen         = sizeof(dirty_writeback_interval),
839                 .mode           = 0644,
840                 .proc_handler   = &dirty_writeback_centisecs_handler,
841         },
842         {
843                 .procname       = "dirty_expire_centisecs",
844                 .data           = &dirty_expire_interval,
845                 .maxlen         = sizeof(dirty_expire_interval),
846                 .mode           = 0644,
847                 .proc_handler   = &proc_dointvec_userhz_jiffies,
848         },
849         {
850                 .ctl_name       = VM_NR_PDFLUSH_THREADS,
851                 .procname       = "nr_pdflush_threads",
852                 .data           = &nr_pdflush_threads,
853                 .maxlen         = sizeof nr_pdflush_threads,
854                 .mode           = 0444 /* read-only*/,
855                 .proc_handler   = &proc_dointvec,
856         },
857         {
858                 .ctl_name       = VM_SWAPPINESS,
859                 .procname       = "swappiness",
860                 .data           = &vm_swappiness,
861                 .maxlen         = sizeof(vm_swappiness),
862                 .mode           = 0644,
863                 .proc_handler   = &proc_dointvec_minmax,
864                 .strategy       = &sysctl_intvec,
865                 .extra1         = &zero,
866                 .extra2         = &one_hundred,
867         },
868 #ifdef CONFIG_HUGETLB_PAGE
869          {
870                 .procname       = "nr_hugepages",
871                 .data           = &max_huge_pages,
872                 .maxlen         = sizeof(unsigned long),
873                 .mode           = 0644,
874                 .proc_handler   = &hugetlb_sysctl_handler,
875                 .extra1         = (void *)&hugetlb_zero,
876                 .extra2         = (void *)&hugetlb_infinity,
877          },
878          {
879                 .ctl_name       = VM_HUGETLB_GROUP,
880                 .procname       = "hugetlb_shm_group",
881                 .data           = &sysctl_hugetlb_shm_group,
882                 .maxlen         = sizeof(gid_t),
883                 .mode           = 0644,
884                 .proc_handler   = &proc_dointvec,
885          },
886          {
887                 .ctl_name       = CTL_UNNUMBERED,
888                 .procname       = "hugepages_treat_as_movable",
889                 .data           = &hugepages_treat_as_movable,
890                 .maxlen         = sizeof(int),
891                 .mode           = 0644,
892                 .proc_handler   = &hugetlb_treat_movable_handler,
893         },
894         {
895                 .ctl_name       = CTL_UNNUMBERED,
896                 .procname       = "hugetlb_dynamic_pool",
897                 .data           = &hugetlb_dynamic_pool,
898                 .maxlen         = sizeof(hugetlb_dynamic_pool),
899                 .mode           = 0644,
900                 .proc_handler   = &proc_dointvec,
901         },
902 #endif
903         {
904                 .ctl_name       = VM_LOWMEM_RESERVE_RATIO,
905                 .procname       = "lowmem_reserve_ratio",
906                 .data           = &sysctl_lowmem_reserve_ratio,
907                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
908                 .mode           = 0644,
909                 .proc_handler   = &lowmem_reserve_ratio_sysctl_handler,
910                 .strategy       = &sysctl_intvec,
911         },
912         {
913                 .ctl_name       = VM_DROP_PAGECACHE,
914                 .procname       = "drop_caches",
915                 .data           = &sysctl_drop_caches,
916                 .maxlen         = sizeof(int),
917                 .mode           = 0644,
918                 .proc_handler   = drop_caches_sysctl_handler,
919                 .strategy       = &sysctl_intvec,
920         },
921         {
922                 .ctl_name       = VM_MIN_FREE_KBYTES,
923                 .procname       = "min_free_kbytes",
924                 .data           = &min_free_kbytes,
925                 .maxlen         = sizeof(min_free_kbytes),
926                 .mode           = 0644,
927                 .proc_handler   = &min_free_kbytes_sysctl_handler,
928                 .strategy       = &sysctl_intvec,
929                 .extra1         = &zero,
930         },
931         {
932                 .ctl_name       = VM_PERCPU_PAGELIST_FRACTION,
933                 .procname       = "percpu_pagelist_fraction",
934                 .data           = &percpu_pagelist_fraction,
935                 .maxlen         = sizeof(percpu_pagelist_fraction),
936                 .mode           = 0644,
937                 .proc_handler   = &percpu_pagelist_fraction_sysctl_handler,
938                 .strategy       = &sysctl_intvec,
939                 .extra1         = &min_percpu_pagelist_fract,
940         },
941 #ifdef CONFIG_MMU
942         {
943                 .ctl_name       = VM_MAX_MAP_COUNT,
944                 .procname       = "max_map_count",
945                 .data           = &sysctl_max_map_count,
946                 .maxlen         = sizeof(sysctl_max_map_count),
947                 .mode           = 0644,
948                 .proc_handler   = &proc_dointvec
949         },
950 #endif
951         {
952                 .ctl_name       = VM_LAPTOP_MODE,
953                 .procname       = "laptop_mode",
954                 .data           = &laptop_mode,
955                 .maxlen         = sizeof(laptop_mode),
956                 .mode           = 0644,
957                 .proc_handler   = &proc_dointvec_jiffies,
958                 .strategy       = &sysctl_jiffies,
959         },
960         {
961                 .ctl_name       = VM_BLOCK_DUMP,
962                 .procname       = "block_dump",
963                 .data           = &block_dump,
964                 .maxlen         = sizeof(block_dump),
965                 .mode           = 0644,
966                 .proc_handler   = &proc_dointvec,
967                 .strategy       = &sysctl_intvec,
968                 .extra1         = &zero,
969         },
970         {
971                 .ctl_name       = VM_VFS_CACHE_PRESSURE,
972                 .procname       = "vfs_cache_pressure",
973                 .data           = &sysctl_vfs_cache_pressure,
974                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
975                 .mode           = 0644,
976                 .proc_handler   = &proc_dointvec,
977                 .strategy       = &sysctl_intvec,
978                 .extra1         = &zero,
979         },
980 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
981         {
982                 .ctl_name       = VM_LEGACY_VA_LAYOUT,
983                 .procname       = "legacy_va_layout",
984                 .data           = &sysctl_legacy_va_layout,
985                 .maxlen         = sizeof(sysctl_legacy_va_layout),
986                 .mode           = 0644,
987                 .proc_handler   = &proc_dointvec,
988                 .strategy       = &sysctl_intvec,
989                 .extra1         = &zero,
990         },
991 #endif
992 #ifdef CONFIG_NUMA
993         {
994                 .ctl_name       = VM_ZONE_RECLAIM_MODE,
995                 .procname       = "zone_reclaim_mode",
996                 .data           = &zone_reclaim_mode,
997                 .maxlen         = sizeof(zone_reclaim_mode),
998                 .mode           = 0644,
999                 .proc_handler   = &proc_dointvec,
1000                 .strategy       = &sysctl_intvec,
1001                 .extra1         = &zero,
1002         },
1003         {
1004                 .ctl_name       = VM_MIN_UNMAPPED,
1005                 .procname       = "min_unmapped_ratio",
1006                 .data           = &sysctl_min_unmapped_ratio,
1007                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1008                 .mode           = 0644,
1009                 .proc_handler   = &sysctl_min_unmapped_ratio_sysctl_handler,
1010                 .strategy       = &sysctl_intvec,
1011                 .extra1         = &zero,
1012                 .extra2         = &one_hundred,
1013         },
1014         {
1015                 .ctl_name       = VM_MIN_SLAB,
1016                 .procname       = "min_slab_ratio",
1017                 .data           = &sysctl_min_slab_ratio,
1018                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1019                 .mode           = 0644,
1020                 .proc_handler   = &sysctl_min_slab_ratio_sysctl_handler,
1021                 .strategy       = &sysctl_intvec,
1022                 .extra1         = &zero,
1023                 .extra2         = &one_hundred,
1024         },
1025 #endif
1026 #ifdef CONFIG_SMP
1027         {
1028                 .ctl_name       = CTL_UNNUMBERED,
1029                 .procname       = "stat_interval",
1030                 .data           = &sysctl_stat_interval,
1031                 .maxlen         = sizeof(sysctl_stat_interval),
1032                 .mode           = 0644,
1033                 .proc_handler   = &proc_dointvec_jiffies,
1034                 .strategy       = &sysctl_jiffies,
1035         },
1036 #endif
1037 #ifdef CONFIG_SECURITY
1038         {
1039                 .ctl_name       = CTL_UNNUMBERED,
1040                 .procname       = "mmap_min_addr",
1041                 .data           = &mmap_min_addr,
1042                 .maxlen         = sizeof(unsigned long),
1043                 .mode           = 0644,
1044                 .proc_handler   = &proc_doulongvec_minmax,
1045         },
1046 #endif
1047 #ifdef CONFIG_NUMA
1048         {
1049                 .ctl_name       = CTL_UNNUMBERED,
1050                 .procname       = "numa_zonelist_order",
1051                 .data           = &numa_zonelist_order,
1052                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1053                 .mode           = 0644,
1054                 .proc_handler   = &numa_zonelist_order_handler,
1055                 .strategy       = &sysctl_string,
1056         },
1057 #endif
1058 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1059    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1060         {
1061                 .ctl_name       = VM_VDSO_ENABLED,
1062                 .procname       = "vdso_enabled",
1063                 .data           = &vdso_enabled,
1064                 .maxlen         = sizeof(vdso_enabled),
1065                 .mode           = 0644,
1066                 .proc_handler   = &proc_dointvec,
1067                 .strategy       = &sysctl_intvec,
1068                 .extra1         = &zero,
1069         },
1070 #endif
1071 /*
1072  * NOTE: do not add new entries to this table unless you have read
1073  * Documentation/sysctl/ctl_unnumbered.txt
1074  */
1075         { .ctl_name = 0 }
1076 };
1077
1078 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1079 static struct ctl_table binfmt_misc_table[] = {
1080         { .ctl_name = 0 }
1081 };
1082 #endif
1083
1084 static struct ctl_table fs_table[] = {
1085         {
1086                 .ctl_name       = FS_NRINODE,
1087                 .procname       = "inode-nr",
1088                 .data           = &inodes_stat,
1089                 .maxlen         = 2*sizeof(int),
1090                 .mode           = 0444,
1091                 .proc_handler   = &proc_dointvec,
1092         },
1093         {
1094                 .ctl_name       = FS_STATINODE,
1095                 .procname       = "inode-state",
1096                 .data           = &inodes_stat,
1097                 .maxlen         = 7*sizeof(int),
1098                 .mode           = 0444,
1099                 .proc_handler   = &proc_dointvec,
1100         },
1101         {
1102                 .procname       = "file-nr",
1103                 .data           = &files_stat,
1104                 .maxlen         = 3*sizeof(int),
1105                 .mode           = 0444,
1106                 .proc_handler   = &proc_nr_files,
1107         },
1108         {
1109                 .ctl_name       = FS_MAXFILE,
1110                 .procname       = "file-max",
1111                 .data           = &files_stat.max_files,
1112                 .maxlen         = sizeof(int),
1113                 .mode           = 0644,
1114                 .proc_handler   = &proc_dointvec,
1115         },
1116         {
1117                 .ctl_name       = FS_DENTRY,
1118                 .procname       = "dentry-state",
1119                 .data           = &dentry_stat,
1120                 .maxlen         = 6*sizeof(int),
1121                 .mode           = 0444,
1122                 .proc_handler   = &proc_dointvec,
1123         },
1124         {
1125                 .ctl_name       = FS_OVERFLOWUID,
1126                 .procname       = "overflowuid",
1127                 .data           = &fs_overflowuid,
1128                 .maxlen         = sizeof(int),
1129                 .mode           = 0644,
1130                 .proc_handler   = &proc_dointvec_minmax,
1131                 .strategy       = &sysctl_intvec,
1132                 .extra1         = &minolduid,
1133                 .extra2         = &maxolduid,
1134         },
1135         {
1136                 .ctl_name       = FS_OVERFLOWGID,
1137                 .procname       = "overflowgid",
1138                 .data           = &fs_overflowgid,
1139                 .maxlen         = sizeof(int),
1140                 .mode           = 0644,
1141                 .proc_handler   = &proc_dointvec_minmax,
1142                 .strategy       = &sysctl_intvec,
1143                 .extra1         = &minolduid,
1144                 .extra2         = &maxolduid,
1145         },
1146         {
1147                 .ctl_name       = FS_LEASES,
1148                 .procname       = "leases-enable",
1149                 .data           = &leases_enable,
1150                 .maxlen         = sizeof(int),
1151                 .mode           = 0644,
1152                 .proc_handler   = &proc_dointvec,
1153         },
1154 #ifdef CONFIG_DNOTIFY
1155         {
1156                 .ctl_name       = FS_DIR_NOTIFY,
1157                 .procname       = "dir-notify-enable",
1158                 .data           = &dir_notify_enable,
1159                 .maxlen         = sizeof(int),
1160                 .mode           = 0644,
1161                 .proc_handler   = &proc_dointvec,
1162         },
1163 #endif
1164 #ifdef CONFIG_MMU
1165         {
1166                 .ctl_name       = FS_LEASE_TIME,
1167                 .procname       = "lease-break-time",
1168                 .data           = &lease_break_time,
1169                 .maxlen         = sizeof(int),
1170                 .mode           = 0644,
1171                 .proc_handler   = &proc_dointvec_minmax,
1172                 .strategy       = &sysctl_intvec,
1173                 .extra1         = &zero,
1174                 .extra2         = &two,
1175         },
1176         {
1177                 .procname       = "aio-nr",
1178                 .data           = &aio_nr,
1179                 .maxlen         = sizeof(aio_nr),
1180                 .mode           = 0444,
1181                 .proc_handler   = &proc_doulongvec_minmax,
1182         },
1183         {
1184                 .procname       = "aio-max-nr",
1185                 .data           = &aio_max_nr,
1186                 .maxlen         = sizeof(aio_max_nr),
1187                 .mode           = 0644,
1188                 .proc_handler   = &proc_doulongvec_minmax,
1189         },
1190 #ifdef CONFIG_INOTIFY_USER
1191         {
1192                 .ctl_name       = FS_INOTIFY,
1193                 .procname       = "inotify",
1194                 .mode           = 0555,
1195                 .child          = inotify_table,
1196         },
1197 #endif  
1198 #endif
1199         {
1200                 .ctl_name       = KERN_SETUID_DUMPABLE,
1201                 .procname       = "suid_dumpable",
1202                 .data           = &suid_dumpable,
1203                 .maxlen         = sizeof(int),
1204                 .mode           = 0644,
1205                 .proc_handler   = &proc_dointvec,
1206         },
1207 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1208         {
1209                 .ctl_name       = CTL_UNNUMBERED,
1210                 .procname       = "binfmt_misc",
1211                 .mode           = 0555,
1212                 .child          = binfmt_misc_table,
1213         },
1214 #endif
1215 /*
1216  * NOTE: do not add new entries to this table unless you have read
1217  * Documentation/sysctl/ctl_unnumbered.txt
1218  */
1219         { .ctl_name = 0 }
1220 };
1221
1222 static struct ctl_table debug_table[] = {
1223 #if defined(CONFIG_X86) || defined(CONFIG_PPC)
1224         {
1225                 .ctl_name       = CTL_UNNUMBERED,
1226                 .procname       = "exception-trace",
1227                 .data           = &show_unhandled_signals,
1228                 .maxlen         = sizeof(int),
1229                 .mode           = 0644,
1230                 .proc_handler   = proc_dointvec
1231         },
1232 #endif
1233         { .ctl_name = 0 }
1234 };
1235
1236 static struct ctl_table dev_table[] = {
1237         { .ctl_name = 0 }
1238 };
1239
1240 static DEFINE_SPINLOCK(sysctl_lock);
1241
1242 /* called under sysctl_lock */
1243 static int use_table(struct ctl_table_header *p)
1244 {
1245         if (unlikely(p->unregistering))
1246                 return 0;
1247         p->used++;
1248         return 1;
1249 }
1250
1251 /* called under sysctl_lock */
1252 static void unuse_table(struct ctl_table_header *p)
1253 {
1254         if (!--p->used)
1255                 if (unlikely(p->unregistering))
1256                         complete(p->unregistering);
1257 }
1258
1259 /* called under sysctl_lock, will reacquire if has to wait */
1260 static void start_unregistering(struct ctl_table_header *p)
1261 {
1262         /*
1263          * if p->used is 0, nobody will ever touch that entry again;
1264          * we'll eliminate all paths to it before dropping sysctl_lock
1265          */
1266         if (unlikely(p->used)) {
1267                 struct completion wait;
1268                 init_completion(&wait);
1269                 p->unregistering = &wait;
1270                 spin_unlock(&sysctl_lock);
1271                 wait_for_completion(&wait);
1272                 spin_lock(&sysctl_lock);
1273         }
1274         /*
1275          * do not remove from the list until nobody holds it; walking the
1276          * list in do_sysctl() relies on that.
1277          */
1278         list_del_init(&p->ctl_entry);
1279 }
1280
1281 void sysctl_head_finish(struct ctl_table_header *head)
1282 {
1283         if (!head)
1284                 return;
1285         spin_lock(&sysctl_lock);
1286         unuse_table(head);
1287         spin_unlock(&sysctl_lock);
1288 }
1289
1290 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1291 {
1292         struct ctl_table_header *head;
1293         struct list_head *tmp;
1294         spin_lock(&sysctl_lock);
1295         if (prev) {
1296                 tmp = &prev->ctl_entry;
1297                 unuse_table(prev);
1298                 goto next;
1299         }
1300         tmp = &root_table_header.ctl_entry;
1301         for (;;) {
1302                 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1303
1304                 if (!use_table(head))
1305                         goto next;
1306                 spin_unlock(&sysctl_lock);
1307                 return head;
1308         next:
1309                 tmp = tmp->next;
1310                 if (tmp == &root_table_header.ctl_entry)
1311                         break;
1312         }
1313         spin_unlock(&sysctl_lock);
1314         return NULL;
1315 }
1316
1317 #ifdef CONFIG_SYSCTL_SYSCALL
1318 int do_sysctl(int __user *name, int nlen, void __user *oldval, size_t __user *oldlenp,
1319                void __user *newval, size_t newlen)
1320 {
1321         struct ctl_table_header *head;
1322         int error = -ENOTDIR;
1323
1324         if (nlen <= 0 || nlen >= CTL_MAXNAME)
1325                 return -ENOTDIR;
1326         if (oldval) {
1327                 int old_len;
1328                 if (!oldlenp || get_user(old_len, oldlenp))
1329                         return -EFAULT;
1330         }
1331
1332         for (head = sysctl_head_next(NULL); head;
1333                         head = sysctl_head_next(head)) {
1334                 error = parse_table(name, nlen, oldval, oldlenp, 
1335                                         newval, newlen, head->ctl_table);
1336                 if (error != -ENOTDIR) {
1337                         sysctl_head_finish(head);
1338                         break;
1339                 }
1340         }
1341         return error;
1342 }
1343
1344 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
1345 {
1346         struct __sysctl_args tmp;
1347         int error;
1348
1349         if (copy_from_user(&tmp, args, sizeof(tmp)))
1350                 return -EFAULT;
1351
1352         error = deprecated_sysctl_warning(&tmp);
1353         if (error)
1354                 goto out;
1355
1356         lock_kernel();
1357         error = do_sysctl(tmp.name, tmp.nlen, tmp.oldval, tmp.oldlenp,
1358                           tmp.newval, tmp.newlen);
1359         unlock_kernel();
1360 out:
1361         return error;
1362 }
1363 #endif /* CONFIG_SYSCTL_SYSCALL */
1364
1365 /*
1366  * sysctl_perm does NOT grant the superuser all rights automatically, because
1367  * some sysctl variables are readonly even to root.
1368  */
1369
1370 static int test_perm(int mode, int op)
1371 {
1372         if (!current->euid)
1373                 mode >>= 6;
1374         else if (in_egroup_p(0))
1375                 mode >>= 3;
1376         if ((mode & op & 0007) == op)
1377                 return 0;
1378         return -EACCES;
1379 }
1380
1381 int sysctl_perm(struct ctl_table *table, int op)
1382 {
1383         int error;
1384         error = security_sysctl(table, op);
1385         if (error)
1386                 return error;
1387         return test_perm(table->mode, op);
1388 }
1389
1390 #ifdef CONFIG_SYSCTL_SYSCALL
1391 static int parse_table(int __user *name, int nlen,
1392                        void __user *oldval, size_t __user *oldlenp,
1393                        void __user *newval, size_t newlen,
1394                        struct ctl_table *table)
1395 {
1396         int n;
1397 repeat:
1398         if (!nlen)
1399                 return -ENOTDIR;
1400         if (get_user(n, name))
1401                 return -EFAULT;
1402         for ( ; table->ctl_name || table->procname; table++) {
1403                 if (!table->ctl_name)
1404                         continue;
1405                 if (n == table->ctl_name) {
1406                         int error;
1407                         if (table->child) {
1408                                 if (sysctl_perm(table, 001))
1409                                         return -EPERM;
1410                                 name++;
1411                                 nlen--;
1412                                 table = table->child;
1413                                 goto repeat;
1414                         }
1415                         error = do_sysctl_strategy(table, name, nlen,
1416                                                    oldval, oldlenp,
1417                                                    newval, newlen);
1418                         return error;
1419                 }
1420         }
1421         return -ENOTDIR;
1422 }
1423
1424 /* Perform the actual read/write of a sysctl table entry. */
1425 int do_sysctl_strategy (struct ctl_table *table,
1426                         int __user *name, int nlen,
1427                         void __user *oldval, size_t __user *oldlenp,
1428                         void __user *newval, size_t newlen)
1429 {
1430         int op = 0, rc;
1431
1432         if (oldval)
1433                 op |= 004;
1434         if (newval) 
1435                 op |= 002;
1436         if (sysctl_perm(table, op))
1437                 return -EPERM;
1438
1439         if (table->strategy) {
1440                 rc = table->strategy(table, name, nlen, oldval, oldlenp,
1441                                      newval, newlen);
1442                 if (rc < 0)
1443                         return rc;
1444                 if (rc > 0)
1445                         return 0;
1446         }
1447
1448         /* If there is no strategy routine, or if the strategy returns
1449          * zero, proceed with automatic r/w */
1450         if (table->data && table->maxlen) {
1451                 rc = sysctl_data(table, name, nlen, oldval, oldlenp,
1452                                  newval, newlen);
1453                 if (rc < 0)
1454                         return rc;
1455         }
1456         return 0;
1457 }
1458 #endif /* CONFIG_SYSCTL_SYSCALL */
1459
1460 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1461 {
1462         for (; table->ctl_name || table->procname; table++) {
1463                 table->parent = parent;
1464                 if (table->child)
1465                         sysctl_set_parent(table, table->child);
1466         }
1467 }
1468
1469 static __init int sysctl_init(void)
1470 {
1471         int err;
1472         sysctl_set_parent(NULL, root_table);
1473         err = sysctl_check_table(root_table);
1474         return 0;
1475 }
1476
1477 core_initcall(sysctl_init);
1478
1479 /**
1480  * register_sysctl_table - register a sysctl hierarchy
1481  * @table: the top-level table structure
1482  *
1483  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1484  * array. An entry with a ctl_name of 0 terminates the table. 
1485  *
1486  * The members of the &struct ctl_table structure are used as follows:
1487  *
1488  * ctl_name - This is the numeric sysctl value used by sysctl(2). The number
1489  *            must be unique within that level of sysctl
1490  *
1491  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1492  *            enter a sysctl file
1493  *
1494  * data - a pointer to data for use by proc_handler
1495  *
1496  * maxlen - the maximum size in bytes of the data
1497  *
1498  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1499  *
1500  * child - a pointer to the child sysctl table if this entry is a directory, or
1501  *         %NULL.
1502  *
1503  * proc_handler - the text handler routine (described below)
1504  *
1505  * strategy - the strategy routine (described below)
1506  *
1507  * de - for internal use by the sysctl routines
1508  *
1509  * extra1, extra2 - extra pointers usable by the proc handler routines
1510  *
1511  * Leaf nodes in the sysctl tree will be represented by a single file
1512  * under /proc; non-leaf nodes will be represented by directories.
1513  *
1514  * sysctl(2) can automatically manage read and write requests through
1515  * the sysctl table.  The data and maxlen fields of the ctl_table
1516  * struct enable minimal validation of the values being written to be
1517  * performed, and the mode field allows minimal authentication.
1518  *
1519  * More sophisticated management can be enabled by the provision of a
1520  * strategy routine with the table entry.  This will be called before
1521  * any automatic read or write of the data is performed.
1522  *
1523  * The strategy routine may return
1524  *
1525  * < 0 - Error occurred (error is passed to user process)
1526  *
1527  * 0   - OK - proceed with automatic read or write.
1528  *
1529  * > 0 - OK - read or write has been done by the strategy routine, so
1530  *       return immediately.
1531  *
1532  * There must be a proc_handler routine for any terminal nodes
1533  * mirrored under /proc/sys (non-terminals are handled by a built-in
1534  * directory handler).  Several default handlers are available to
1535  * cover common cases -
1536  *
1537  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1538  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1539  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1540  *
1541  * It is the handler's job to read the input buffer from user memory
1542  * and process it. The handler should return 0 on success.
1543  *
1544  * This routine returns %NULL on a failure to register, and a pointer
1545  * to the table header on success.
1546  */
1547 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1548 {
1549         struct ctl_table_header *tmp;
1550         tmp = kmalloc(sizeof(struct ctl_table_header), GFP_KERNEL);
1551         if (!tmp)
1552                 return NULL;
1553         tmp->ctl_table = table;
1554         INIT_LIST_HEAD(&tmp->ctl_entry);
1555         tmp->used = 0;
1556         tmp->unregistering = NULL;
1557         sysctl_set_parent(NULL, table);
1558         if (sysctl_check_table(tmp->ctl_table)) {
1559                 kfree(tmp);
1560                 return NULL;
1561         }
1562         spin_lock(&sysctl_lock);
1563         list_add_tail(&tmp->ctl_entry, &root_table_header.ctl_entry);
1564         spin_unlock(&sysctl_lock);
1565         return tmp;
1566 }
1567
1568 /**
1569  * unregister_sysctl_table - unregister a sysctl table hierarchy
1570  * @header: the header returned from register_sysctl_table
1571  *
1572  * Unregisters the sysctl table and all children. proc entries may not
1573  * actually be removed until they are no longer used by anyone.
1574  */
1575 void unregister_sysctl_table(struct ctl_table_header * header)
1576 {
1577         might_sleep();
1578         spin_lock(&sysctl_lock);
1579         start_unregistering(header);
1580         spin_unlock(&sysctl_lock);
1581         kfree(header);
1582 }
1583
1584 #else /* !CONFIG_SYSCTL */
1585 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1586 {
1587         return NULL;
1588 }
1589
1590 void unregister_sysctl_table(struct ctl_table_header * table)
1591 {
1592 }
1593
1594 #endif /* CONFIG_SYSCTL */
1595
1596 /*
1597  * /proc/sys support
1598  */
1599
1600 #ifdef CONFIG_PROC_SYSCTL
1601
1602 static int _proc_do_string(void* data, int maxlen, int write,
1603                            struct file *filp, void __user *buffer,
1604                            size_t *lenp, loff_t *ppos)
1605 {
1606         size_t len;
1607         char __user *p;
1608         char c;
1609
1610         if (!data || !maxlen || !*lenp) {
1611                 *lenp = 0;
1612                 return 0;
1613         }
1614
1615         if (write) {
1616                 len = 0;
1617                 p = buffer;
1618                 while (len < *lenp) {
1619                         if (get_user(c, p++))
1620                                 return -EFAULT;
1621                         if (c == 0 || c == '\n')
1622                                 break;
1623                         len++;
1624                 }
1625                 if (len >= maxlen)
1626                         len = maxlen-1;
1627                 if(copy_from_user(data, buffer, len))
1628                         return -EFAULT;
1629                 ((char *) data)[len] = 0;
1630                 *ppos += *lenp;
1631         } else {
1632                 len = strlen(data);
1633                 if (len > maxlen)
1634                         len = maxlen;
1635
1636                 if (*ppos > len) {
1637                         *lenp = 0;
1638                         return 0;
1639                 }
1640
1641                 data += *ppos;
1642                 len  -= *ppos;
1643
1644                 if (len > *lenp)
1645                         len = *lenp;
1646                 if (len)
1647                         if(copy_to_user(buffer, data, len))
1648                                 return -EFAULT;
1649                 if (len < *lenp) {
1650                         if(put_user('\n', ((char __user *) buffer) + len))
1651                                 return -EFAULT;
1652                         len++;
1653                 }
1654                 *lenp = len;
1655                 *ppos += len;
1656         }
1657         return 0;
1658 }
1659
1660 /**
1661  * proc_dostring - read a string sysctl
1662  * @table: the sysctl table
1663  * @write: %TRUE if this is a write to the sysctl file
1664  * @filp: the file structure
1665  * @buffer: the user buffer
1666  * @lenp: the size of the user buffer
1667  * @ppos: file position
1668  *
1669  * Reads/writes a string from/to the user buffer. If the kernel
1670  * buffer provided is not large enough to hold the string, the
1671  * string is truncated. The copied string is %NULL-terminated.
1672  * If the string is being read by the user process, it is copied
1673  * and a newline '\n' is added. It is truncated if the buffer is
1674  * not large enough.
1675  *
1676  * Returns 0 on success.
1677  */
1678 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
1679                   void __user *buffer, size_t *lenp, loff_t *ppos)
1680 {
1681         return _proc_do_string(table->data, table->maxlen, write, filp,
1682                                buffer, lenp, ppos);
1683 }
1684
1685
1686 static int do_proc_dointvec_conv(int *negp, unsigned long *lvalp,
1687                                  int *valp,
1688                                  int write, void *data)
1689 {
1690         if (write) {
1691                 *valp = *negp ? -*lvalp : *lvalp;
1692         } else {
1693                 int val = *valp;
1694                 if (val < 0) {
1695                         *negp = -1;
1696                         *lvalp = (unsigned long)-val;
1697                 } else {
1698                         *negp = 0;
1699                         *lvalp = (unsigned long)val;
1700                 }
1701         }
1702         return 0;
1703 }
1704
1705 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
1706                   int write, struct file *filp, void __user *buffer,
1707                   size_t *lenp, loff_t *ppos,
1708                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1709                               int write, void *data),
1710                   void *data)
1711 {
1712 #define TMPBUFLEN 21
1713         int *i, vleft, first=1, neg, val;
1714         unsigned long lval;
1715         size_t left, len;
1716         
1717         char buf[TMPBUFLEN], *p;
1718         char __user *s = buffer;
1719         
1720         if (!tbl_data || !table->maxlen || !*lenp ||
1721             (*ppos && !write)) {
1722                 *lenp = 0;
1723                 return 0;
1724         }
1725         
1726         i = (int *) tbl_data;
1727         vleft = table->maxlen / sizeof(*i);
1728         left = *lenp;
1729
1730         if (!conv)
1731                 conv = do_proc_dointvec_conv;
1732
1733         for (; left && vleft--; i++, first=0) {
1734                 if (write) {
1735                         while (left) {
1736                                 char c;
1737                                 if (get_user(c, s))
1738                                         return -EFAULT;
1739                                 if (!isspace(c))
1740                                         break;
1741                                 left--;
1742                                 s++;
1743                         }
1744                         if (!left)
1745                                 break;
1746                         neg = 0;
1747                         len = left;
1748                         if (len > sizeof(buf) - 1)
1749                                 len = sizeof(buf) - 1;
1750                         if (copy_from_user(buf, s, len))
1751                                 return -EFAULT;
1752                         buf[len] = 0;
1753                         p = buf;
1754                         if (*p == '-' && left > 1) {
1755                                 neg = 1;
1756                                 p++;
1757                         }
1758                         if (*p < '0' || *p > '9')
1759                                 break;
1760
1761                         lval = simple_strtoul(p, &p, 0);
1762
1763                         len = p-buf;
1764                         if ((len < left) && *p && !isspace(*p))
1765                                 break;
1766                         if (neg)
1767                                 val = -val;
1768                         s += len;
1769                         left -= len;
1770
1771                         if (conv(&neg, &lval, i, 1, data))
1772                                 break;
1773                 } else {
1774                         p = buf;
1775                         if (!first)
1776                                 *p++ = '\t';
1777         
1778                         if (conv(&neg, &lval, i, 0, data))
1779                                 break;
1780
1781                         sprintf(p, "%s%lu", neg ? "-" : "", lval);
1782                         len = strlen(buf);
1783                         if (len > left)
1784                                 len = left;
1785                         if(copy_to_user(s, buf, len))
1786                                 return -EFAULT;
1787                         left -= len;
1788                         s += len;
1789                 }
1790         }
1791
1792         if (!write && !first && left) {
1793                 if(put_user('\n', s))
1794                         return -EFAULT;
1795                 left--, s++;
1796         }
1797         if (write) {
1798                 while (left) {
1799                         char c;
1800                         if (get_user(c, s++))
1801                                 return -EFAULT;
1802                         if (!isspace(c))
1803                                 break;
1804                         left--;
1805                 }
1806         }
1807         if (write && first)
1808                 return -EINVAL;
1809         *lenp -= left;
1810         *ppos += *lenp;
1811         return 0;
1812 #undef TMPBUFLEN
1813 }
1814
1815 static int do_proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1816                   void __user *buffer, size_t *lenp, loff_t *ppos,
1817                   int (*conv)(int *negp, unsigned long *lvalp, int *valp,
1818                               int write, void *data),
1819                   void *data)
1820 {
1821         return __do_proc_dointvec(table->data, table, write, filp,
1822                         buffer, lenp, ppos, conv, data);
1823 }
1824
1825 /**
1826  * proc_dointvec - read a vector of integers
1827  * @table: the sysctl table
1828  * @write: %TRUE if this is a write to the sysctl file
1829  * @filp: the file structure
1830  * @buffer: the user buffer
1831  * @lenp: the size of the user buffer
1832  * @ppos: file position
1833  *
1834  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1835  * values from/to the user buffer, treated as an ASCII string. 
1836  *
1837  * Returns 0 on success.
1838  */
1839 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
1840                      void __user *buffer, size_t *lenp, loff_t *ppos)
1841 {
1842     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1843                             NULL,NULL);
1844 }
1845
1846 #define OP_SET  0
1847 #define OP_AND  1
1848 #define OP_OR   2
1849
1850 static int do_proc_dointvec_bset_conv(int *negp, unsigned long *lvalp,
1851                                       int *valp,
1852                                       int write, void *data)
1853 {
1854         int op = *(int *)data;
1855         if (write) {
1856                 int val = *negp ? -*lvalp : *lvalp;
1857                 switch(op) {
1858                 case OP_SET:    *valp = val; break;
1859                 case OP_AND:    *valp &= val; break;
1860                 case OP_OR:     *valp |= val; break;
1861                 }
1862         } else {
1863                 int val = *valp;
1864                 if (val < 0) {
1865                         *negp = -1;
1866                         *lvalp = (unsigned long)-val;
1867                 } else {
1868                         *negp = 0;
1869                         *lvalp = (unsigned long)val;
1870                 }
1871         }
1872         return 0;
1873 }
1874
1875 /*
1876  *      init may raise the set.
1877  */
1878  
1879 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
1880                         void __user *buffer, size_t *lenp, loff_t *ppos)
1881 {
1882         int op;
1883
1884         if (write && !capable(CAP_SYS_MODULE)) {
1885                 return -EPERM;
1886         }
1887
1888         op = is_init(current) ? OP_SET : OP_AND;
1889         return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1890                                 do_proc_dointvec_bset_conv,&op);
1891 }
1892
1893 /*
1894  *      Taint values can only be increased
1895  */
1896 static int proc_dointvec_taint(struct ctl_table *table, int write, struct file *filp,
1897                                void __user *buffer, size_t *lenp, loff_t *ppos)
1898 {
1899         int op;
1900
1901         if (write && !capable(CAP_SYS_ADMIN))
1902                 return -EPERM;
1903
1904         op = OP_OR;
1905         return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
1906                                 do_proc_dointvec_bset_conv,&op);
1907 }
1908
1909 struct do_proc_dointvec_minmax_conv_param {
1910         int *min;
1911         int *max;
1912 };
1913
1914 static int do_proc_dointvec_minmax_conv(int *negp, unsigned long *lvalp, 
1915                                         int *valp, 
1916                                         int write, void *data)
1917 {
1918         struct do_proc_dointvec_minmax_conv_param *param = data;
1919         if (write) {
1920                 int val = *negp ? -*lvalp : *lvalp;
1921                 if ((param->min && *param->min > val) ||
1922                     (param->max && *param->max < val))
1923                         return -EINVAL;
1924                 *valp = val;
1925         } else {
1926                 int val = *valp;
1927                 if (val < 0) {
1928                         *negp = -1;
1929                         *lvalp = (unsigned long)-val;
1930                 } else {
1931                         *negp = 0;
1932                         *lvalp = (unsigned long)val;
1933                 }
1934         }
1935         return 0;
1936 }
1937
1938 /**
1939  * proc_dointvec_minmax - read a vector of integers with min/max values
1940  * @table: the sysctl table
1941  * @write: %TRUE if this is a write to the sysctl file
1942  * @filp: the file structure
1943  * @buffer: the user buffer
1944  * @lenp: the size of the user buffer
1945  * @ppos: file position
1946  *
1947  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
1948  * values from/to the user buffer, treated as an ASCII string.
1949  *
1950  * This routine will ensure the values are within the range specified by
1951  * table->extra1 (min) and table->extra2 (max).
1952  *
1953  * Returns 0 on success.
1954  */
1955 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
1956                   void __user *buffer, size_t *lenp, loff_t *ppos)
1957 {
1958         struct do_proc_dointvec_minmax_conv_param param = {
1959                 .min = (int *) table->extra1,
1960                 .max = (int *) table->extra2,
1961         };
1962         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
1963                                 do_proc_dointvec_minmax_conv, &param);
1964 }
1965
1966 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
1967                                      struct file *filp,
1968                                      void __user *buffer,
1969                                      size_t *lenp, loff_t *ppos,
1970                                      unsigned long convmul,
1971                                      unsigned long convdiv)
1972 {
1973 #define TMPBUFLEN 21
1974         unsigned long *i, *min, *max, val;
1975         int vleft, first=1, neg;
1976         size_t len, left;
1977         char buf[TMPBUFLEN], *p;
1978         char __user *s = buffer;
1979         
1980         if (!data || !table->maxlen || !*lenp ||
1981             (*ppos && !write)) {
1982                 *lenp = 0;
1983                 return 0;
1984         }
1985         
1986         i = (unsigned long *) data;
1987         min = (unsigned long *) table->extra1;
1988         max = (unsigned long *) table->extra2;
1989         vleft = table->maxlen / sizeof(unsigned long);
1990         left = *lenp;
1991         
1992         for (; left && vleft--; i++, min++, max++, first=0) {
1993                 if (write) {
1994                         while (left) {
1995                                 char c;
1996                                 if (get_user(c, s))
1997                                         return -EFAULT;
1998                                 if (!isspace(c))
1999                                         break;
2000                                 left--;
2001                                 s++;
2002                         }
2003                         if (!left)
2004                                 break;
2005                         neg = 0;
2006                         len = left;
2007                         if (len > TMPBUFLEN-1)
2008                                 len = TMPBUFLEN-1;
2009                         if (copy_from_user(buf, s, len))
2010                                 return -EFAULT;
2011                         buf[len] = 0;
2012                         p = buf;
2013                         if (*p == '-' && left > 1) {
2014                                 neg = 1;
2015                                 p++;
2016                         }
2017                         if (*p < '0' || *p > '9')
2018                                 break;
2019                         val = simple_strtoul(p, &p, 0) * convmul / convdiv ;
2020                         len = p-buf;
2021                         if ((len < left) && *p && !isspace(*p))
2022                                 break;
2023                         if (neg)
2024                                 val = -val;
2025                         s += len;
2026                         left -= len;
2027
2028                         if(neg)
2029                                 continue;
2030                         if ((min && val < *min) || (max && val > *max))
2031                                 continue;
2032                         *i = val;
2033                 } else {
2034                         p = buf;
2035                         if (!first)
2036                                 *p++ = '\t';
2037                         sprintf(p, "%lu", convdiv * (*i) / convmul);
2038                         len = strlen(buf);
2039                         if (len > left)
2040                                 len = left;
2041                         if(copy_to_user(s, buf, len))
2042                                 return -EFAULT;
2043                         left -= len;
2044                         s += len;
2045                 }
2046         }
2047
2048         if (!write && !first && left) {
2049                 if(put_user('\n', s))
2050                         return -EFAULT;
2051                 left--, s++;
2052         }
2053         if (write) {
2054                 while (left) {
2055                         char c;
2056                         if (get_user(c, s++))
2057                                 return -EFAULT;
2058                         if (!isspace(c))
2059                                 break;
2060                         left--;
2061                 }
2062         }
2063         if (write && first)
2064                 return -EINVAL;
2065         *lenp -= left;
2066         *ppos += *lenp;
2067         return 0;
2068 #undef TMPBUFLEN
2069 }
2070
2071 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2072                                      struct file *filp,
2073                                      void __user *buffer,
2074                                      size_t *lenp, loff_t *ppos,
2075                                      unsigned long convmul,
2076                                      unsigned long convdiv)
2077 {
2078         return __do_proc_doulongvec_minmax(table->data, table, write,
2079                         filp, buffer, lenp, ppos, convmul, convdiv);
2080 }
2081
2082 /**
2083  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2084  * @table: the sysctl table
2085  * @write: %TRUE if this is a write to the sysctl file
2086  * @filp: the file structure
2087  * @buffer: the user buffer
2088  * @lenp: the size of the user buffer
2089  * @ppos: file position
2090  *
2091  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2092  * values from/to the user buffer, treated as an ASCII string.
2093  *
2094  * This routine will ensure the values are within the range specified by
2095  * table->extra1 (min) and table->extra2 (max).
2096  *
2097  * Returns 0 on success.
2098  */
2099 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2100                            void __user *buffer, size_t *lenp, loff_t *ppos)
2101 {
2102     return do_proc_doulongvec_minmax(table, write, filp, buffer, lenp, ppos, 1l, 1l);
2103 }
2104
2105 /**
2106  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2107  * @table: the sysctl table
2108  * @write: %TRUE if this is a write to the sysctl file
2109  * @filp: the file structure
2110  * @buffer: the user buffer
2111  * @lenp: the size of the user buffer
2112  * @ppos: file position
2113  *
2114  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2115  * values from/to the user buffer, treated as an ASCII string. The values
2116  * are treated as milliseconds, and converted to jiffies when they are stored.
2117  *
2118  * This routine will ensure the values are within the range specified by
2119  * table->extra1 (min) and table->extra2 (max).
2120  *
2121  * Returns 0 on success.
2122  */
2123 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2124                                       struct file *filp,
2125                                       void __user *buffer,
2126                                       size_t *lenp, loff_t *ppos)
2127 {
2128     return do_proc_doulongvec_minmax(table, write, filp, buffer,
2129                                      lenp, ppos, HZ, 1000l);
2130 }
2131
2132
2133 static int do_proc_dointvec_jiffies_conv(int *negp, unsigned long *lvalp,
2134                                          int *valp,
2135                                          int write, void *data)
2136 {
2137         if (write) {
2138                 if (*lvalp > LONG_MAX / HZ)
2139                         return 1;
2140                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2141         } else {
2142                 int val = *valp;
2143                 unsigned long lval;
2144                 if (val < 0) {
2145                         *negp = -1;
2146                         lval = (unsigned long)-val;
2147                 } else {
2148                         *negp = 0;
2149                         lval = (unsigned long)val;
2150                 }
2151                 *lvalp = lval / HZ;
2152         }
2153         return 0;
2154 }
2155
2156 static int do_proc_dointvec_userhz_jiffies_conv(int *negp, unsigned long *lvalp,
2157                                                 int *valp,
2158                                                 int write, void *data)
2159 {
2160         if (write) {
2161                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2162                         return 1;
2163                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2164         } else {
2165                 int val = *valp;
2166                 unsigned long lval;
2167                 if (val < 0) {
2168                         *negp = -1;
2169                         lval = (unsigned long)-val;
2170                 } else {
2171                         *negp = 0;
2172                         lval = (unsigned long)val;
2173                 }
2174                 *lvalp = jiffies_to_clock_t(lval);
2175         }
2176         return 0;
2177 }
2178
2179 static int do_proc_dointvec_ms_jiffies_conv(int *negp, unsigned long *lvalp,
2180                                             int *valp,
2181                                             int write, void *data)
2182 {
2183         if (write) {
2184                 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2185         } else {
2186                 int val = *valp;
2187                 unsigned long lval;
2188                 if (val < 0) {
2189                         *negp = -1;
2190                         lval = (unsigned long)-val;
2191                 } else {
2192                         *negp = 0;
2193                         lval = (unsigned long)val;
2194                 }
2195                 *lvalp = jiffies_to_msecs(lval);
2196         }
2197         return 0;
2198 }
2199
2200 /**
2201  * proc_dointvec_jiffies - read a vector of integers as seconds
2202  * @table: the sysctl table
2203  * @write: %TRUE if this is a write to the sysctl file
2204  * @filp: the file structure
2205  * @buffer: the user buffer
2206  * @lenp: the size of the user buffer
2207  * @ppos: file position
2208  *
2209  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2210  * values from/to the user buffer, treated as an ASCII string. 
2211  * The values read are assumed to be in seconds, and are converted into
2212  * jiffies.
2213  *
2214  * Returns 0 on success.
2215  */
2216 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2217                           void __user *buffer, size_t *lenp, loff_t *ppos)
2218 {
2219     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2220                             do_proc_dointvec_jiffies_conv,NULL);
2221 }
2222
2223 /**
2224  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2225  * @table: the sysctl table
2226  * @write: %TRUE if this is a write to the sysctl file
2227  * @filp: the file structure
2228  * @buffer: the user buffer
2229  * @lenp: the size of the user buffer
2230  * @ppos: pointer to the file position
2231  *
2232  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2233  * values from/to the user buffer, treated as an ASCII string. 
2234  * The values read are assumed to be in 1/USER_HZ seconds, and 
2235  * are converted into jiffies.
2236  *
2237  * Returns 0 on success.
2238  */
2239 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2240                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2241 {
2242     return do_proc_dointvec(table,write,filp,buffer,lenp,ppos,
2243                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2244 }
2245
2246 /**
2247  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2248  * @table: the sysctl table
2249  * @write: %TRUE if this is a write to the sysctl file
2250  * @filp: the file structure
2251  * @buffer: the user buffer
2252  * @lenp: the size of the user buffer
2253  * @ppos: file position
2254  * @ppos: the current position in the file
2255  *
2256  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2257  * values from/to the user buffer, treated as an ASCII string. 
2258  * The values read are assumed to be in 1/1000 seconds, and 
2259  * are converted into jiffies.
2260  *
2261  * Returns 0 on success.
2262  */
2263 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2264                              void __user *buffer, size_t *lenp, loff_t *ppos)
2265 {
2266         return do_proc_dointvec(table, write, filp, buffer, lenp, ppos,
2267                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2268 }
2269
2270 static int proc_do_cad_pid(struct ctl_table *table, int write, struct file *filp,
2271                            void __user *buffer, size_t *lenp, loff_t *ppos)
2272 {
2273         struct pid *new_pid;
2274         pid_t tmp;
2275         int r;
2276
2277         tmp = pid_nr(cad_pid);
2278
2279         r = __do_proc_dointvec(&tmp, table, write, filp, buffer,
2280                                lenp, ppos, NULL, NULL);
2281         if (r || !write)
2282                 return r;
2283
2284         new_pid = find_get_pid(tmp);
2285         if (!new_pid)
2286                 return -ESRCH;
2287
2288         put_pid(xchg(&cad_pid, new_pid));
2289         return 0;
2290 }
2291
2292 #else /* CONFIG_PROC_FS */
2293
2294 int proc_dostring(struct ctl_table *table, int write, struct file *filp,
2295                   void __user *buffer, size_t *lenp, loff_t *ppos)
2296 {
2297         return -ENOSYS;
2298 }
2299
2300 int proc_dointvec(struct ctl_table *table, int write, struct file *filp,
2301                   void __user *buffer, size_t *lenp, loff_t *ppos)
2302 {
2303         return -ENOSYS;
2304 }
2305
2306 int proc_dointvec_bset(struct ctl_table *table, int write, struct file *filp,
2307                         void __user *buffer, size_t *lenp, loff_t *ppos)
2308 {
2309         return -ENOSYS;
2310 }
2311
2312 int proc_dointvec_minmax(struct ctl_table *table, int write, struct file *filp,
2313                     void __user *buffer, size_t *lenp, loff_t *ppos)
2314 {
2315         return -ENOSYS;
2316 }
2317
2318 int proc_dointvec_jiffies(struct ctl_table *table, int write, struct file *filp,
2319                     void __user *buffer, size_t *lenp, loff_t *ppos)
2320 {
2321         return -ENOSYS;
2322 }
2323
2324 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, struct file *filp,
2325                     void __user *buffer, size_t *lenp, loff_t *ppos)
2326 {
2327         return -ENOSYS;
2328 }
2329
2330 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, struct file *filp,
2331                              void __user *buffer, size_t *lenp, loff_t *ppos)
2332 {
2333         return -ENOSYS;
2334 }
2335
2336 int proc_doulongvec_minmax(struct ctl_table *table, int write, struct file *filp,
2337                     void __user *buffer, size_t *lenp, loff_t *ppos)
2338 {
2339         return -ENOSYS;
2340 }
2341
2342 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2343                                       struct file *filp,
2344                                       void __user *buffer,
2345                                       size_t *lenp, loff_t *ppos)
2346 {
2347     return -ENOSYS;
2348 }
2349
2350
2351 #endif /* CONFIG_PROC_FS */
2352
2353
2354 #ifdef CONFIG_SYSCTL_SYSCALL
2355 /*
2356  * General sysctl support routines 
2357  */
2358
2359 /* The generic sysctl data routine (used if no strategy routine supplied) */
2360 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2361                 void __user *oldval, size_t __user *oldlenp,
2362                 void __user *newval, size_t newlen)
2363 {
2364         size_t len;
2365
2366         /* Get out of I don't have a variable */
2367         if (!table->data || !table->maxlen)
2368                 return -ENOTDIR;
2369
2370         if (oldval && oldlenp) {
2371                 if (get_user(len, oldlenp))
2372                         return -EFAULT;
2373                 if (len) {
2374                         if (len > table->maxlen)
2375                                 len = table->maxlen;
2376                         if (copy_to_user(oldval, table->data, len))
2377                                 return -EFAULT;
2378                         if (put_user(len, oldlenp))
2379                                 return -EFAULT;
2380                 }
2381         }
2382
2383         if (newval && newlen) {
2384                 if (newlen > table->maxlen)
2385                         newlen = table->maxlen;
2386
2387                 if (copy_from_user(table->data, newval, newlen))
2388                         return -EFAULT;
2389         }
2390         return 1;
2391 }
2392
2393 /* The generic string strategy routine: */
2394 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2395                   void __user *oldval, size_t __user *oldlenp,
2396                   void __user *newval, size_t newlen)
2397 {
2398         if (!table->data || !table->maxlen) 
2399                 return -ENOTDIR;
2400         
2401         if (oldval && oldlenp) {
2402                 size_t bufsize;
2403                 if (get_user(bufsize, oldlenp))
2404                         return -EFAULT;
2405                 if (bufsize) {
2406                         size_t len = strlen(table->data), copied;
2407
2408                         /* This shouldn't trigger for a well-formed sysctl */
2409                         if (len > table->maxlen)
2410                                 len = table->maxlen;
2411
2412                         /* Copy up to a max of bufsize-1 bytes of the string */
2413                         copied = (len >= bufsize) ? bufsize - 1 : len;
2414
2415                         if (copy_to_user(oldval, table->data, copied) ||
2416                             put_user(0, (char __user *)(oldval + copied)))
2417                                 return -EFAULT;
2418                         if (put_user(len, oldlenp))
2419                                 return -EFAULT;
2420                 }
2421         }
2422         if (newval && newlen) {
2423                 size_t len = newlen;
2424                 if (len > table->maxlen)
2425                         len = table->maxlen;
2426                 if(copy_from_user(table->data, newval, len))
2427                         return -EFAULT;
2428                 if (len == table->maxlen)
2429                         len--;
2430                 ((char *) table->data)[len] = 0;
2431         }
2432         return 1;
2433 }
2434
2435 /*
2436  * This function makes sure that all of the integers in the vector
2437  * are between the minimum and maximum values given in the arrays
2438  * table->extra1 and table->extra2, respectively.
2439  */
2440 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2441                 void __user *oldval, size_t __user *oldlenp,
2442                 void __user *newval, size_t newlen)
2443 {
2444
2445         if (newval && newlen) {
2446                 int __user *vec = (int __user *) newval;
2447                 int *min = (int *) table->extra1;
2448                 int *max = (int *) table->extra2;
2449                 size_t length;
2450                 int i;
2451
2452                 if (newlen % sizeof(int) != 0)
2453                         return -EINVAL;
2454
2455                 if (!table->extra1 && !table->extra2)
2456                         return 0;
2457
2458                 if (newlen > table->maxlen)
2459                         newlen = table->maxlen;
2460                 length = newlen / sizeof(int);
2461
2462                 for (i = 0; i < length; i++) {
2463                         int value;
2464                         if (get_user(value, vec + i))
2465                                 return -EFAULT;
2466                         if (min && value < min[i])
2467                                 return -EINVAL;
2468                         if (max && value > max[i])
2469                                 return -EINVAL;
2470                 }
2471         }
2472         return 0;
2473 }
2474
2475 /* Strategy function to convert jiffies to seconds */ 
2476 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2477                 void __user *oldval, size_t __user *oldlenp,
2478                 void __user *newval, size_t newlen)
2479 {
2480         if (oldval && oldlenp) {
2481                 size_t olen;
2482
2483                 if (get_user(olen, oldlenp))
2484                         return -EFAULT;
2485                 if (olen) {
2486                         int val;
2487
2488                         if (olen < sizeof(int))
2489                                 return -EINVAL;
2490
2491                         val = *(int *)(table->data) / HZ;
2492                         if (put_user(val, (int __user *)oldval))
2493                                 return -EFAULT;
2494                         if (put_user(sizeof(int), oldlenp))
2495                                 return -EFAULT;
2496                 }
2497         }
2498         if (newval && newlen) { 
2499                 int new;
2500                 if (newlen != sizeof(int))
2501                         return -EINVAL; 
2502                 if (get_user(new, (int __user *)newval))
2503                         return -EFAULT;
2504                 *(int *)(table->data) = new*HZ; 
2505         }
2506         return 1;
2507 }
2508
2509 /* Strategy function to convert jiffies to seconds */ 
2510 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2511                 void __user *oldval, size_t __user *oldlenp,
2512                 void __user *newval, size_t newlen)
2513 {
2514         if (oldval && oldlenp) {
2515                 size_t olen;
2516
2517                 if (get_user(olen, oldlenp))
2518                         return -EFAULT;
2519                 if (olen) {
2520                         int val;
2521
2522                         if (olen < sizeof(int))
2523                                 return -EINVAL;
2524
2525                         val = jiffies_to_msecs(*(int *)(table->data));
2526                         if (put_user(val, (int __user *)oldval))
2527                                 return -EFAULT;
2528                         if (put_user(sizeof(int), oldlenp))
2529                                 return -EFAULT;
2530                 }
2531         }
2532         if (newval && newlen) { 
2533                 int new;
2534                 if (newlen != sizeof(int))
2535                         return -EINVAL; 
2536                 if (get_user(new, (int __user *)newval))
2537                         return -EFAULT;
2538                 *(int *)(table->data) = msecs_to_jiffies(new);
2539         }
2540         return 1;
2541 }
2542
2543
2544
2545 #else /* CONFIG_SYSCTL_SYSCALL */
2546
2547
2548 asmlinkage long sys_sysctl(struct __sysctl_args __user *args)
2549 {
2550         struct __sysctl_args tmp;
2551         int error;
2552
2553         if (copy_from_user(&tmp, args, sizeof(tmp)))
2554                 return -EFAULT;
2555
2556         error = deprecated_sysctl_warning(&tmp);
2557
2558         /* If no error reading the parameters then just -ENOSYS ... */
2559         if (!error)
2560                 error = -ENOSYS;
2561
2562         return error;
2563 }
2564
2565 int sysctl_data(struct ctl_table *table, int __user *name, int nlen,
2566                   void __user *oldval, size_t __user *oldlenp,
2567                   void __user *newval, size_t newlen)
2568 {
2569         return -ENOSYS;
2570 }
2571
2572 int sysctl_string(struct ctl_table *table, int __user *name, int nlen,
2573                   void __user *oldval, size_t __user *oldlenp,
2574                   void __user *newval, size_t newlen)
2575 {
2576         return -ENOSYS;
2577 }
2578
2579 int sysctl_intvec(struct ctl_table *table, int __user *name, int nlen,
2580                 void __user *oldval, size_t __user *oldlenp,
2581                 void __user *newval, size_t newlen)
2582 {
2583         return -ENOSYS;
2584 }
2585
2586 int sysctl_jiffies(struct ctl_table *table, int __user *name, int nlen,
2587                 void __user *oldval, size_t __user *oldlenp,
2588                 void __user *newval, size_t newlen)
2589 {
2590         return -ENOSYS;
2591 }
2592
2593 int sysctl_ms_jiffies(struct ctl_table *table, int __user *name, int nlen,
2594                 void __user *oldval, size_t __user *oldlenp,
2595                 void __user *newval, size_t newlen)
2596 {
2597         return -ENOSYS;
2598 }
2599
2600 #endif /* CONFIG_SYSCTL_SYSCALL */
2601
2602 static int deprecated_sysctl_warning(struct __sysctl_args *args)
2603 {
2604         static int msg_count;
2605         int name[CTL_MAXNAME];
2606         int i;
2607
2608         /* Read in the sysctl name for better debug message logging */
2609         for (i = 0; i < args->nlen; i++)
2610                 if (get_user(name[i], args->name + i))
2611                         return -EFAULT;
2612
2613         /* Ignore accesses to kernel.version */
2614         if ((args->nlen == 2) && (name[0] == CTL_KERN) && (name[1] == KERN_VERSION))
2615                 return 0;
2616
2617         if (msg_count < 5) {
2618                 msg_count++;
2619                 printk(KERN_INFO
2620                         "warning: process `%s' used the deprecated sysctl "
2621                         "system call with ", current->comm);
2622                 for (i = 0; i < args->nlen; i++)
2623                         printk("%d.", name[i]);
2624                 printk("\n");
2625         }
2626         return 0;
2627 }
2628
2629 /*
2630  * No sense putting this after each symbol definition, twice,
2631  * exception granted :-)
2632  */
2633 EXPORT_SYMBOL(proc_dointvec);
2634 EXPORT_SYMBOL(proc_dointvec_jiffies);
2635 EXPORT_SYMBOL(proc_dointvec_minmax);
2636 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2637 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2638 EXPORT_SYMBOL(proc_dostring);
2639 EXPORT_SYMBOL(proc_doulongvec_minmax);
2640 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2641 EXPORT_SYMBOL(register_sysctl_table);
2642 EXPORT_SYMBOL(sysctl_intvec);
2643 EXPORT_SYMBOL(sysctl_jiffies);
2644 EXPORT_SYMBOL(sysctl_ms_jiffies);
2645 EXPORT_SYMBOL(sysctl_string);
2646 EXPORT_SYMBOL(sysctl_data);
2647 EXPORT_SYMBOL(unregister_sysctl_table);