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