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