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