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