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