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