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