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