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