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