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