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