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