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