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