]> git.karo-electronics.de Git - karo-tx-linux.git/blob - kernel/sysctl.c
Add a proc_dointvec_unsigned() sysctl handler for positive value cases.
[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_minmax,
1198                 .extra1         = &zero,
1199         },
1200 #else
1201         {
1202                 .procname       = "nr_trim_pages",
1203                 .data           = &sysctl_nr_trim_pages,
1204                 .maxlen         = sizeof(sysctl_nr_trim_pages),
1205                 .mode           = 0644,
1206                 .proc_handler   = proc_dointvec_minmax,
1207                 .extra1         = &zero,
1208         },
1209 #endif
1210         {
1211                 .procname       = "laptop_mode",
1212                 .data           = &laptop_mode,
1213                 .maxlen         = sizeof(laptop_mode),
1214                 .mode           = 0644,
1215                 .proc_handler   = proc_dointvec_jiffies,
1216         },
1217         {
1218                 .procname       = "block_dump",
1219                 .data           = &block_dump,
1220                 .maxlen         = sizeof(block_dump),
1221                 .mode           = 0644,
1222                 .proc_handler   = proc_dointvec,
1223                 .extra1         = &zero,
1224         },
1225         {
1226                 .procname       = "vfs_cache_pressure",
1227                 .data           = &sysctl_vfs_cache_pressure,
1228                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
1229                 .mode           = 0644,
1230                 .proc_handler   = proc_dointvec,
1231                 .extra1         = &zero,
1232         },
1233 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1234         {
1235                 .procname       = "legacy_va_layout",
1236                 .data           = &sysctl_legacy_va_layout,
1237                 .maxlen         = sizeof(sysctl_legacy_va_layout),
1238                 .mode           = 0644,
1239                 .proc_handler   = proc_dointvec,
1240                 .extra1         = &zero,
1241         },
1242 #endif
1243 #ifdef CONFIG_NUMA
1244         {
1245                 .procname       = "zone_reclaim_mode",
1246                 .data           = &zone_reclaim_mode,
1247                 .maxlen         = sizeof(zone_reclaim_mode),
1248                 .mode           = 0644,
1249                 .proc_handler   = proc_dointvec,
1250                 .extra1         = &zero,
1251         },
1252         {
1253                 .procname       = "min_unmapped_ratio",
1254                 .data           = &sysctl_min_unmapped_ratio,
1255                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1256                 .mode           = 0644,
1257                 .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
1258                 .extra1         = &zero,
1259                 .extra2         = &one_hundred,
1260         },
1261         {
1262                 .procname       = "min_slab_ratio",
1263                 .data           = &sysctl_min_slab_ratio,
1264                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1265                 .mode           = 0644,
1266                 .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
1267                 .extra1         = &zero,
1268                 .extra2         = &one_hundred,
1269         },
1270 #endif
1271 #ifdef CONFIG_SMP
1272         {
1273                 .procname       = "stat_interval",
1274                 .data           = &sysctl_stat_interval,
1275                 .maxlen         = sizeof(sysctl_stat_interval),
1276                 .mode           = 0644,
1277                 .proc_handler   = proc_dointvec_jiffies,
1278         },
1279 #endif
1280 #ifdef CONFIG_MMU
1281         {
1282                 .procname       = "mmap_min_addr",
1283                 .data           = &dac_mmap_min_addr,
1284                 .maxlen         = sizeof(unsigned long),
1285                 .mode           = 0644,
1286                 .proc_handler   = mmap_min_addr_handler,
1287         },
1288 #endif
1289 #ifdef CONFIG_NUMA
1290         {
1291                 .procname       = "numa_zonelist_order",
1292                 .data           = &numa_zonelist_order,
1293                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1294                 .mode           = 0644,
1295                 .proc_handler   = numa_zonelist_order_handler,
1296         },
1297 #endif
1298 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1299    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1300         {
1301                 .procname       = "vdso_enabled",
1302                 .data           = &vdso_enabled,
1303                 .maxlen         = sizeof(vdso_enabled),
1304                 .mode           = 0644,
1305                 .proc_handler   = proc_dointvec,
1306                 .extra1         = &zero,
1307         },
1308 #endif
1309 #ifdef CONFIG_HIGHMEM
1310         {
1311                 .procname       = "highmem_is_dirtyable",
1312                 .data           = &vm_highmem_is_dirtyable,
1313                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
1314                 .mode           = 0644,
1315                 .proc_handler   = proc_dointvec_bool,
1316         },
1317 #endif
1318         {
1319                 .procname       = "scan_unevictable_pages",
1320                 .data           = &scan_unevictable_pages,
1321                 .maxlen         = sizeof(scan_unevictable_pages),
1322                 .mode           = 0644,
1323                 .proc_handler   = scan_unevictable_handler,
1324         },
1325 #ifdef CONFIG_MEMORY_FAILURE
1326         {
1327                 .procname       = "memory_failure_early_kill",
1328                 .data           = &sysctl_memory_failure_early_kill,
1329                 .maxlen         = sizeof(sysctl_memory_failure_early_kill),
1330                 .mode           = 0644,
1331                 .proc_handler   = proc_dointvec_bool,
1332         },
1333         {
1334                 .procname       = "memory_failure_recovery",
1335                 .data           = &sysctl_memory_failure_recovery,
1336                 .maxlen         = sizeof(sysctl_memory_failure_recovery),
1337                 .mode           = 0644,
1338                 .proc_handler   = proc_dointvec_bool,
1339         },
1340 #endif
1341         { }
1342 };
1343
1344 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1345 static struct ctl_table binfmt_misc_table[] = {
1346         { }
1347 };
1348 #endif
1349
1350 static struct ctl_table fs_table[] = {
1351         {
1352                 .procname       = "inode-nr",
1353                 .data           = &inodes_stat,
1354                 .maxlen         = 2*sizeof(int),
1355                 .mode           = 0444,
1356                 .proc_handler   = proc_nr_inodes,
1357         },
1358         {
1359                 .procname       = "inode-state",
1360                 .data           = &inodes_stat,
1361                 .maxlen         = 7*sizeof(int),
1362                 .mode           = 0444,
1363                 .proc_handler   = proc_nr_inodes,
1364         },
1365         {
1366                 .procname       = "file-nr",
1367                 .data           = &files_stat,
1368                 .maxlen         = sizeof(files_stat),
1369                 .mode           = 0444,
1370                 .proc_handler   = proc_nr_files,
1371         },
1372         {
1373                 .procname       = "file-max",
1374                 .data           = &files_stat.max_files,
1375                 .maxlen         = sizeof(files_stat.max_files),
1376                 .mode           = 0644,
1377                 .proc_handler   = proc_doulongvec_minmax,
1378         },
1379         {
1380                 .procname       = "nr_open",
1381                 .data           = &sysctl_nr_open,
1382                 .maxlen         = sizeof(int),
1383                 .mode           = 0644,
1384                 .proc_handler   = proc_dointvec_minmax,
1385                 .extra1         = &sysctl_nr_open_min,
1386                 .extra2         = &sysctl_nr_open_max,
1387         },
1388         {
1389                 .procname       = "dentry-state",
1390                 .data           = &dentry_stat,
1391                 .maxlen         = 6*sizeof(int),
1392                 .mode           = 0444,
1393                 .proc_handler   = proc_nr_dentry,
1394         },
1395         {
1396                 .procname       = "overflowuid",
1397                 .data           = &fs_overflowuid,
1398                 .maxlen         = sizeof(int),
1399                 .mode           = 0644,
1400                 .proc_handler   = proc_dointvec_minmax,
1401                 .extra1         = &minolduid,
1402                 .extra2         = &maxolduid,
1403         },
1404         {
1405                 .procname       = "overflowgid",
1406                 .data           = &fs_overflowgid,
1407                 .maxlen         = sizeof(int),
1408                 .mode           = 0644,
1409                 .proc_handler   = proc_dointvec_minmax,
1410                 .extra1         = &minolduid,
1411                 .extra2         = &maxolduid,
1412         },
1413 #ifdef CONFIG_FILE_LOCKING
1414         {
1415                 .procname       = "leases-enable",
1416                 .data           = &leases_enable,
1417                 .maxlen         = sizeof(int),
1418                 .mode           = 0644,
1419                 .proc_handler   = proc_dointvec,
1420         },
1421 #endif
1422 #ifdef CONFIG_DNOTIFY
1423         {
1424                 .procname       = "dir-notify-enable",
1425                 .data           = &dir_notify_enable,
1426                 .maxlen         = sizeof(int),
1427                 .mode           = 0644,
1428                 .proc_handler   = proc_dointvec,
1429         },
1430 #endif
1431 #ifdef CONFIG_MMU
1432 #ifdef CONFIG_FILE_LOCKING
1433         {
1434                 .procname       = "lease-break-time",
1435                 .data           = &lease_break_time,
1436                 .maxlen         = sizeof(int),
1437                 .mode           = 0644,
1438                 .proc_handler   = proc_dointvec,
1439         },
1440 #endif
1441 #ifdef CONFIG_AIO
1442         {
1443                 .procname       = "aio-nr",
1444                 .data           = &aio_nr,
1445                 .maxlen         = sizeof(aio_nr),
1446                 .mode           = 0444,
1447                 .proc_handler   = proc_doulongvec_minmax,
1448         },
1449         {
1450                 .procname       = "aio-max-nr",
1451                 .data           = &aio_max_nr,
1452                 .maxlen         = sizeof(aio_max_nr),
1453                 .mode           = 0644,
1454                 .proc_handler   = proc_doulongvec_minmax,
1455         },
1456 #endif /* CONFIG_AIO */
1457 #ifdef CONFIG_INOTIFY_USER
1458         {
1459                 .procname       = "inotify",
1460                 .mode           = 0555,
1461                 .child          = inotify_table,
1462         },
1463 #endif  
1464 #ifdef CONFIG_EPOLL
1465         {
1466                 .procname       = "epoll",
1467                 .mode           = 0555,
1468                 .child          = epoll_table,
1469         },
1470 #endif
1471 #endif
1472         {
1473                 .procname       = "suid_dumpable",
1474                 .data           = &suid_dumpable,
1475                 .maxlen         = sizeof(int),
1476                 .mode           = 0644,
1477                 .proc_handler   = proc_dointvec_minmax,
1478                 .extra1         = &zero,
1479                 .extra2         = &two,
1480         },
1481 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1482         {
1483                 .procname       = "binfmt_misc",
1484                 .mode           = 0555,
1485                 .child          = binfmt_misc_table,
1486         },
1487 #endif
1488         {
1489                 .procname       = "pipe-max-size",
1490                 .data           = &pipe_max_size,
1491                 .maxlen         = sizeof(int),
1492                 .mode           = 0644,
1493                 .proc_handler   = &pipe_proc_fn,
1494                 .extra1         = &pipe_min_size,
1495         },
1496         { }
1497 };
1498
1499 static struct ctl_table debug_table[] = {
1500 #if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_SPARC) || \
1501     defined(CONFIG_S390) || defined(CONFIG_TILE)
1502         {
1503                 .procname       = "exception-trace",
1504                 .data           = &show_unhandled_signals,
1505                 .maxlen         = sizeof(int),
1506                 .mode           = 0644,
1507                 .proc_handler   = proc_dointvec
1508         },
1509 #endif
1510 #if defined(CONFIG_OPTPROBES)
1511         {
1512                 .procname       = "kprobes-optimization",
1513                 .data           = &sysctl_kprobes_optimization,
1514                 .maxlen         = sizeof(int),
1515                 .mode           = 0644,
1516                 .proc_handler   = proc_kprobes_optimization_handler,
1517                 .extra1         = &zero,
1518                 .extra2         = &one,
1519         },
1520 #endif
1521         { }
1522 };
1523
1524 static struct ctl_table dev_table[] = {
1525         { }
1526 };
1527
1528 static DEFINE_SPINLOCK(sysctl_lock);
1529
1530 /* called under sysctl_lock */
1531 static int use_table(struct ctl_table_header *p)
1532 {
1533         if (unlikely(p->unregistering))
1534                 return 0;
1535         p->used++;
1536         return 1;
1537 }
1538
1539 /* called under sysctl_lock */
1540 static void unuse_table(struct ctl_table_header *p)
1541 {
1542         if (!--p->used)
1543                 if (unlikely(p->unregistering))
1544                         complete(p->unregistering);
1545 }
1546
1547 /* called under sysctl_lock, will reacquire if has to wait */
1548 static void start_unregistering(struct ctl_table_header *p)
1549 {
1550         /*
1551          * if p->used is 0, nobody will ever touch that entry again;
1552          * we'll eliminate all paths to it before dropping sysctl_lock
1553          */
1554         if (unlikely(p->used)) {
1555                 struct completion wait;
1556                 init_completion(&wait);
1557                 p->unregistering = &wait;
1558                 spin_unlock(&sysctl_lock);
1559                 wait_for_completion(&wait);
1560                 spin_lock(&sysctl_lock);
1561         } else {
1562                 /* anything non-NULL; we'll never dereference it */
1563                 p->unregistering = ERR_PTR(-EINVAL);
1564         }
1565         /*
1566          * do not remove from the list until nobody holds it; walking the
1567          * list in do_sysctl() relies on that.
1568          */
1569         list_del_init(&p->ctl_entry);
1570 }
1571
1572 void sysctl_head_get(struct ctl_table_header *head)
1573 {
1574         spin_lock(&sysctl_lock);
1575         head->count++;
1576         spin_unlock(&sysctl_lock);
1577 }
1578
1579 void sysctl_head_put(struct ctl_table_header *head)
1580 {
1581         spin_lock(&sysctl_lock);
1582         if (!--head->count)
1583                 kfree_rcu(head, rcu);
1584         spin_unlock(&sysctl_lock);
1585 }
1586
1587 struct ctl_table_header *sysctl_head_grab(struct ctl_table_header *head)
1588 {
1589         if (!head)
1590                 BUG();
1591         spin_lock(&sysctl_lock);
1592         if (!use_table(head))
1593                 head = ERR_PTR(-ENOENT);
1594         spin_unlock(&sysctl_lock);
1595         return head;
1596 }
1597
1598 void sysctl_head_finish(struct ctl_table_header *head)
1599 {
1600         if (!head)
1601                 return;
1602         spin_lock(&sysctl_lock);
1603         unuse_table(head);
1604         spin_unlock(&sysctl_lock);
1605 }
1606
1607 static struct ctl_table_set *
1608 lookup_header_set(struct ctl_table_root *root, struct nsproxy *namespaces)
1609 {
1610         struct ctl_table_set *set = &root->default_set;
1611         if (root->lookup)
1612                 set = root->lookup(root, namespaces);
1613         return set;
1614 }
1615
1616 static struct list_head *
1617 lookup_header_list(struct ctl_table_root *root, struct nsproxy *namespaces)
1618 {
1619         struct ctl_table_set *set = lookup_header_set(root, namespaces);
1620         return &set->list;
1621 }
1622
1623 struct ctl_table_header *__sysctl_head_next(struct nsproxy *namespaces,
1624                                             struct ctl_table_header *prev)
1625 {
1626         struct ctl_table_root *root;
1627         struct list_head *header_list;
1628         struct ctl_table_header *head;
1629         struct list_head *tmp;
1630
1631         spin_lock(&sysctl_lock);
1632         if (prev) {
1633                 head = prev;
1634                 tmp = &prev->ctl_entry;
1635                 unuse_table(prev);
1636                 goto next;
1637         }
1638         tmp = &root_table_header.ctl_entry;
1639         for (;;) {
1640                 head = list_entry(tmp, struct ctl_table_header, ctl_entry);
1641
1642                 if (!use_table(head))
1643                         goto next;
1644                 spin_unlock(&sysctl_lock);
1645                 return head;
1646         next:
1647                 root = head->root;
1648                 tmp = tmp->next;
1649                 header_list = lookup_header_list(root, namespaces);
1650                 if (tmp != header_list)
1651                         continue;
1652
1653                 do {
1654                         root = list_entry(root->root_list.next,
1655                                         struct ctl_table_root, root_list);
1656                         if (root == &sysctl_table_root)
1657                                 goto out;
1658                         header_list = lookup_header_list(root, namespaces);
1659                 } while (list_empty(header_list));
1660                 tmp = header_list->next;
1661         }
1662 out:
1663         spin_unlock(&sysctl_lock);
1664         return NULL;
1665 }
1666
1667 struct ctl_table_header *sysctl_head_next(struct ctl_table_header *prev)
1668 {
1669         return __sysctl_head_next(current->nsproxy, prev);
1670 }
1671
1672 void register_sysctl_root(struct ctl_table_root *root)
1673 {
1674         spin_lock(&sysctl_lock);
1675         list_add_tail(&root->root_list, &sysctl_table_root.root_list);
1676         spin_unlock(&sysctl_lock);
1677 }
1678
1679 /*
1680  * sysctl_perm does NOT grant the superuser all rights automatically, because
1681  * some sysctl variables are readonly even to root.
1682  */
1683
1684 static int test_perm(int mode, int op)
1685 {
1686         if (!current_euid())
1687                 mode >>= 6;
1688         else if (in_egroup_p(0))
1689                 mode >>= 3;
1690         if ((op & ~mode & (MAY_READ|MAY_WRITE|MAY_EXEC)) == 0)
1691                 return 0;
1692         return -EACCES;
1693 }
1694
1695 int sysctl_perm(struct ctl_table_root *root, struct ctl_table *table, int op)
1696 {
1697         int mode;
1698
1699         if (root->permissions)
1700                 mode = root->permissions(root, current->nsproxy, table);
1701         else
1702                 mode = table->mode;
1703
1704         return test_perm(mode, op);
1705 }
1706
1707 static void sysctl_set_parent(struct ctl_table *parent, struct ctl_table *table)
1708 {
1709         for (; table->procname; table++) {
1710                 table->parent = parent;
1711                 if (table->child)
1712                         sysctl_set_parent(table, table->child);
1713         }
1714 }
1715
1716 static __init int sysctl_init(void)
1717 {
1718         sysctl_set_parent(NULL, root_table);
1719 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1720         sysctl_check_table(current->nsproxy, root_table);
1721 #endif
1722         return 0;
1723 }
1724
1725 core_initcall(sysctl_init);
1726
1727 static struct ctl_table *is_branch_in(struct ctl_table *branch,
1728                                       struct ctl_table *table)
1729 {
1730         struct ctl_table *p;
1731         const char *s = branch->procname;
1732
1733         /* branch should have named subdirectory as its first element */
1734         if (!s || !branch->child)
1735                 return NULL;
1736
1737         /* ... and nothing else */
1738         if (branch[1].procname)
1739                 return NULL;
1740
1741         /* table should contain subdirectory with the same name */
1742         for (p = table; p->procname; p++) {
1743                 if (!p->child)
1744                         continue;
1745                 if (p->procname && strcmp(p->procname, s) == 0)
1746                         return p;
1747         }
1748         return NULL;
1749 }
1750
1751 /* see if attaching q to p would be an improvement */
1752 static void try_attach(struct ctl_table_header *p, struct ctl_table_header *q)
1753 {
1754         struct ctl_table *to = p->ctl_table, *by = q->ctl_table;
1755         struct ctl_table *next;
1756         int is_better = 0;
1757         int not_in_parent = !p->attached_by;
1758
1759         while ((next = is_branch_in(by, to)) != NULL) {
1760                 if (by == q->attached_by)
1761                         is_better = 1;
1762                 if (to == p->attached_by)
1763                         not_in_parent = 1;
1764                 by = by->child;
1765                 to = next->child;
1766         }
1767
1768         if (is_better && not_in_parent) {
1769                 q->attached_by = by;
1770                 q->attached_to = to;
1771                 q->parent = p;
1772         }
1773 }
1774
1775 /**
1776  * __register_sysctl_paths - register a sysctl hierarchy
1777  * @root: List of sysctl headers to register on
1778  * @namespaces: Data to compute which lists of sysctl entries are visible
1779  * @path: The path to the directory the sysctl table is in.
1780  * @table: the top-level table structure
1781  *
1782  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1783  * array. A completely 0 filled entry terminates the table.
1784  *
1785  * The members of the &struct ctl_table structure are used as follows:
1786  *
1787  * procname - the name of the sysctl file under /proc/sys. Set to %NULL to not
1788  *            enter a sysctl file
1789  *
1790  * data - a pointer to data for use by proc_handler
1791  *
1792  * maxlen - the maximum size in bytes of the data
1793  *
1794  * mode - the file permissions for the /proc/sys file, and for sysctl(2)
1795  *
1796  * child - a pointer to the child sysctl table if this entry is a directory, or
1797  *         %NULL.
1798  *
1799  * proc_handler - the text handler routine (described below)
1800  *
1801  * de - for internal use by the sysctl routines
1802  *
1803  * extra1, extra2 - extra pointers usable by the proc handler routines
1804  *
1805  * Leaf nodes in the sysctl tree will be represented by a single file
1806  * under /proc; non-leaf nodes will be represented by directories.
1807  *
1808  * sysctl(2) can automatically manage read and write requests through
1809  * the sysctl table.  The data and maxlen fields of the ctl_table
1810  * struct enable minimal validation of the values being written to be
1811  * performed, and the mode field allows minimal authentication.
1812  *
1813  * There must be a proc_handler routine for any terminal nodes
1814  * mirrored under /proc/sys (non-terminals are handled by a built-in
1815  * directory handler).  Several default handlers are available to
1816  * cover common cases -
1817  *
1818  * proc_dostring(), proc_dointvec(), proc_dointvec_jiffies(),
1819  * proc_dointvec_userhz_jiffies(), proc_dointvec_minmax(), 
1820  * proc_doulongvec_ms_jiffies_minmax(), proc_doulongvec_minmax()
1821  *
1822  * It is the handler's job to read the input buffer from user memory
1823  * and process it. The handler should return 0 on success.
1824  *
1825  * This routine returns %NULL on a failure to register, and a pointer
1826  * to the table header on success.
1827  */
1828 struct ctl_table_header *__register_sysctl_paths(
1829         struct ctl_table_root *root,
1830         struct nsproxy *namespaces,
1831         const struct ctl_path *path, struct ctl_table *table)
1832 {
1833         struct ctl_table_header *header;
1834         struct ctl_table *new, **prevp;
1835         unsigned int n, npath;
1836         struct ctl_table_set *set;
1837
1838         /* Count the path components */
1839         for (npath = 0; path[npath].procname; ++npath)
1840                 ;
1841
1842         /*
1843          * For each path component, allocate a 2-element ctl_table array.
1844          * The first array element will be filled with the sysctl entry
1845          * for this, the second will be the sentinel (procname == 0).
1846          *
1847          * We allocate everything in one go so that we don't have to
1848          * worry about freeing additional memory in unregister_sysctl_table.
1849          */
1850         header = kzalloc(sizeof(struct ctl_table_header) +
1851                          (2 * npath * sizeof(struct ctl_table)), GFP_KERNEL);
1852         if (!header)
1853                 return NULL;
1854
1855         new = (struct ctl_table *) (header + 1);
1856
1857         /* Now connect the dots */
1858         prevp = &header->ctl_table;
1859         for (n = 0; n < npath; ++n, ++path) {
1860                 /* Copy the procname */
1861                 new->procname = path->procname;
1862                 new->mode     = 0555;
1863
1864                 *prevp = new;
1865                 prevp = &new->child;
1866
1867                 new += 2;
1868         }
1869         *prevp = table;
1870         header->ctl_table_arg = table;
1871
1872         INIT_LIST_HEAD(&header->ctl_entry);
1873         header->used = 0;
1874         header->unregistering = NULL;
1875         header->root = root;
1876         sysctl_set_parent(NULL, header->ctl_table);
1877         header->count = 1;
1878 #ifdef CONFIG_SYSCTL_SYSCALL_CHECK
1879         if (sysctl_check_table(namespaces, header->ctl_table)) {
1880                 kfree(header);
1881                 return NULL;
1882         }
1883 #endif
1884         spin_lock(&sysctl_lock);
1885         header->set = lookup_header_set(root, namespaces);
1886         header->attached_by = header->ctl_table;
1887         header->attached_to = root_table;
1888         header->parent = &root_table_header;
1889         for (set = header->set; set; set = set->parent) {
1890                 struct ctl_table_header *p;
1891                 list_for_each_entry(p, &set->list, ctl_entry) {
1892                         if (p->unregistering)
1893                                 continue;
1894                         try_attach(p, header);
1895                 }
1896         }
1897         header->parent->count++;
1898         list_add_tail(&header->ctl_entry, &header->set->list);
1899         spin_unlock(&sysctl_lock);
1900
1901         return header;
1902 }
1903
1904 /**
1905  * register_sysctl_table_path - register a sysctl table hierarchy
1906  * @path: The path to the directory the sysctl table is in.
1907  * @table: the top-level table structure
1908  *
1909  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1910  * array. A completely 0 filled entry terminates the table.
1911  *
1912  * See __register_sysctl_paths for more details.
1913  */
1914 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1915                                                 struct ctl_table *table)
1916 {
1917         return __register_sysctl_paths(&sysctl_table_root, current->nsproxy,
1918                                         path, table);
1919 }
1920
1921 /**
1922  * register_sysctl_table - register a sysctl table hierarchy
1923  * @table: the top-level table structure
1924  *
1925  * Register a sysctl table hierarchy. @table should be a filled in ctl_table
1926  * array. A completely 0 filled entry terminates the table.
1927  *
1928  * See register_sysctl_paths for more details.
1929  */
1930 struct ctl_table_header *register_sysctl_table(struct ctl_table *table)
1931 {
1932         static const struct ctl_path null_path[] = { {} };
1933
1934         return register_sysctl_paths(null_path, table);
1935 }
1936
1937 /**
1938  * unregister_sysctl_table - unregister a sysctl table hierarchy
1939  * @header: the header returned from register_sysctl_table
1940  *
1941  * Unregisters the sysctl table and all children. proc entries may not
1942  * actually be removed until they are no longer used by anyone.
1943  */
1944 void unregister_sysctl_table(struct ctl_table_header * header)
1945 {
1946         might_sleep();
1947
1948         if (header == NULL)
1949                 return;
1950
1951         spin_lock(&sysctl_lock);
1952         start_unregistering(header);
1953         if (!--header->parent->count) {
1954                 WARN_ON(1);
1955                 kfree_rcu(header->parent, rcu);
1956         }
1957         if (!--header->count)
1958                 kfree_rcu(header, rcu);
1959         spin_unlock(&sysctl_lock);
1960 }
1961
1962 int sysctl_is_seen(struct ctl_table_header *p)
1963 {
1964         struct ctl_table_set *set = p->set;
1965         int res;
1966         spin_lock(&sysctl_lock);
1967         if (p->unregistering)
1968                 res = 0;
1969         else if (!set->is_seen)
1970                 res = 1;
1971         else
1972                 res = set->is_seen(set);
1973         spin_unlock(&sysctl_lock);
1974         return res;
1975 }
1976
1977 void setup_sysctl_set(struct ctl_table_set *p,
1978         struct ctl_table_set *parent,
1979         int (*is_seen)(struct ctl_table_set *))
1980 {
1981         INIT_LIST_HEAD(&p->list);
1982         p->parent = parent ? parent : &sysctl_table_root.default_set;
1983         p->is_seen = is_seen;
1984 }
1985
1986 #else /* !CONFIG_SYSCTL */
1987 struct ctl_table_header *register_sysctl_table(struct ctl_table * table)
1988 {
1989         return NULL;
1990 }
1991
1992 struct ctl_table_header *register_sysctl_paths(const struct ctl_path *path,
1993                                                     struct ctl_table *table)
1994 {
1995         return NULL;
1996 }
1997
1998 void unregister_sysctl_table(struct ctl_table_header * table)
1999 {
2000 }
2001
2002 void setup_sysctl_set(struct ctl_table_set *p,
2003         struct ctl_table_set *parent,
2004         int (*is_seen)(struct ctl_table_set *))
2005 {
2006 }
2007
2008 void sysctl_head_put(struct ctl_table_header *head)
2009 {
2010 }
2011
2012 #endif /* CONFIG_SYSCTL */
2013
2014 /*
2015  * /proc/sys support
2016  */
2017
2018 #ifdef CONFIG_PROC_SYSCTL
2019
2020 static int _proc_do_string(void* data, int maxlen, int write,
2021                            void __user *buffer,
2022                            size_t *lenp, loff_t *ppos)
2023 {
2024         size_t len;
2025         char __user *p;
2026         char c;
2027
2028         if (!data || !maxlen || !*lenp) {
2029                 *lenp = 0;
2030                 return 0;
2031         }
2032
2033         if (write) {
2034                 len = 0;
2035                 p = buffer;
2036                 while (len < *lenp) {
2037                         if (get_user(c, p++))
2038                                 return -EFAULT;
2039                         if (c == 0 || c == '\n')
2040                                 break;
2041                         len++;
2042                 }
2043                 if (len >= maxlen)
2044                         len = maxlen-1;
2045                 if(copy_from_user(data, buffer, len))
2046                         return -EFAULT;
2047                 ((char *) data)[len] = 0;
2048                 *ppos += *lenp;
2049         } else {
2050                 len = strlen(data);
2051                 if (len > maxlen)
2052                         len = maxlen;
2053
2054                 if (*ppos > len) {
2055                         *lenp = 0;
2056                         return 0;
2057                 }
2058
2059                 data += *ppos;
2060                 len  -= *ppos;
2061
2062                 if (len > *lenp)
2063                         len = *lenp;
2064                 if (len)
2065                         if(copy_to_user(buffer, data, len))
2066                                 return -EFAULT;
2067                 if (len < *lenp) {
2068                         if(put_user('\n', ((char __user *) buffer) + len))
2069                                 return -EFAULT;
2070                         len++;
2071                 }
2072                 *lenp = len;
2073                 *ppos += len;
2074         }
2075         return 0;
2076 }
2077
2078 /**
2079  * proc_dostring - read a string sysctl
2080  * @table: the sysctl table
2081  * @write: %TRUE if this is a write to the sysctl file
2082  * @buffer: the user buffer
2083  * @lenp: the size of the user buffer
2084  * @ppos: file position
2085  *
2086  * Reads/writes a string from/to the user buffer. If the kernel
2087  * buffer provided is not large enough to hold the string, the
2088  * string is truncated. The copied string is %NULL-terminated.
2089  * If the string is being read by the user process, it is copied
2090  * and a newline '\n' is added. It is truncated if the buffer is
2091  * not large enough.
2092  *
2093  * Returns 0 on success.
2094  */
2095 int proc_dostring(struct ctl_table *table, int write,
2096                   void __user *buffer, size_t *lenp, loff_t *ppos)
2097 {
2098         return _proc_do_string(table->data, table->maxlen, write,
2099                                buffer, lenp, ppos);
2100 }
2101
2102 static size_t proc_skip_spaces(char **buf)
2103 {
2104         size_t ret;
2105         char *tmp = skip_spaces(*buf);
2106         ret = tmp - *buf;
2107         *buf = tmp;
2108         return ret;
2109 }
2110
2111 static void proc_skip_char(char **buf, size_t *size, const char v)
2112 {
2113         while (*size) {
2114                 if (**buf != v)
2115                         break;
2116                 (*size)--;
2117                 (*buf)++;
2118         }
2119 }
2120
2121 #define TMPBUFLEN 22
2122 /**
2123  * proc_get_long - reads an ASCII formatted integer from a user buffer
2124  *
2125  * @buf: a kernel buffer
2126  * @size: size of the kernel buffer
2127  * @val: this is where the number will be stored
2128  * @neg: set to %TRUE if number is negative
2129  * @perm_tr: a vector which contains the allowed trailers
2130  * @perm_tr_len: size of the perm_tr vector
2131  * @tr: pointer to store the trailer character
2132  *
2133  * In case of success %0 is returned and @buf and @size are updated with
2134  * the amount of bytes read. If @tr is non-NULL and a trailing
2135  * character exists (size is non-zero after returning from this
2136  * function), @tr is updated with the trailing character.
2137  */
2138 static int proc_get_long(char **buf, size_t *size,
2139                           unsigned long *val, bool *neg,
2140                           const char *perm_tr, unsigned perm_tr_len, char *tr)
2141 {
2142         int len;
2143         char *p, tmp[TMPBUFLEN];
2144
2145         if (!*size)
2146                 return -EINVAL;
2147
2148         len = *size;
2149         if (len > TMPBUFLEN - 1)
2150                 len = TMPBUFLEN - 1;
2151
2152         memcpy(tmp, *buf, len);
2153
2154         tmp[len] = 0;
2155         p = tmp;
2156         if (*p == '-' && *size > 1) {
2157                 *neg = true;
2158                 p++;
2159         } else
2160                 *neg = false;
2161         if (!isdigit(*p))
2162                 return -EINVAL;
2163
2164         *val = simple_strtoul(p, &p, 0);
2165
2166         len = p - tmp;
2167
2168         /* We don't know if the next char is whitespace thus we may accept
2169          * invalid integers (e.g. 1234...a) or two integers instead of one
2170          * (e.g. 123...1). So lets not allow such large numbers. */
2171         if (len == TMPBUFLEN - 1)
2172                 return -EINVAL;
2173
2174         if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2175                 return -EINVAL;
2176
2177         if (tr && (len < *size))
2178                 *tr = *p;
2179
2180         *buf += len;
2181         *size -= len;
2182
2183         return 0;
2184 }
2185
2186 /**
2187  * proc_put_long - converts an integer to a decimal ASCII formatted string
2188  *
2189  * @buf: the user buffer
2190  * @size: the size of the user buffer
2191  * @val: the integer to be converted
2192  * @neg: sign of the number, %TRUE for negative
2193  *
2194  * In case of success %0 is returned and @buf and @size are updated with
2195  * the amount of bytes written.
2196  */
2197 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2198                           bool neg)
2199 {
2200         int len;
2201         char tmp[TMPBUFLEN], *p = tmp;
2202
2203         sprintf(p, "%s%lu", neg ? "-" : "", val);
2204         len = strlen(tmp);
2205         if (len > *size)
2206                 len = *size;
2207         if (copy_to_user(*buf, tmp, len))
2208                 return -EFAULT;
2209         *size -= len;
2210         *buf += len;
2211         return 0;
2212 }
2213 #undef TMPBUFLEN
2214
2215 static int proc_put_char(void __user **buf, size_t *size, char c)
2216 {
2217         if (*size) {
2218                 char __user **buffer = (char __user **)buf;
2219                 if (put_user(c, *buffer))
2220                         return -EFAULT;
2221                 (*size)--, (*buffer)++;
2222                 *buf = *buffer;
2223         }
2224         return 0;
2225 }
2226
2227 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2228                                  int *valp,
2229                                  int write, void *data)
2230 {
2231         if (write) {
2232                 *valp = *negp ? -*lvalp : *lvalp;
2233         } else {
2234                 int val = *valp;
2235                 if (val < 0) {
2236                         *negp = true;
2237                         *lvalp = (unsigned long)-val;
2238                 } else {
2239                         *negp = false;
2240                         *lvalp = (unsigned long)val;
2241                 }
2242         }
2243         return 0;
2244 }
2245
2246 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2247
2248 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2249                   int write, void __user *buffer,
2250                   size_t *lenp, loff_t *ppos,
2251                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2252                               int write, void *data),
2253                   void *data)
2254 {
2255         int *i, vleft, first = 1, err = 0;
2256         unsigned long page = 0;
2257         size_t left;
2258         char *kbuf;
2259         
2260         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2261                 *lenp = 0;
2262                 return 0;
2263         }
2264         
2265         i = (int *) tbl_data;
2266         vleft = table->maxlen / sizeof(*i);
2267         left = *lenp;
2268
2269         if (!conv)
2270                 conv = do_proc_dointvec_conv;
2271
2272         if (write) {
2273                 if (left > PAGE_SIZE - 1)
2274                         left = PAGE_SIZE - 1;
2275                 page = __get_free_page(GFP_TEMPORARY);
2276                 kbuf = (char *) page;
2277                 if (!kbuf)
2278                         return -ENOMEM;
2279                 if (copy_from_user(kbuf, buffer, left)) {
2280                         err = -EFAULT;
2281                         goto free;
2282                 }
2283                 kbuf[left] = 0;
2284         }
2285
2286         for (; left && vleft--; i++, first=0) {
2287                 unsigned long lval;
2288                 bool neg;
2289
2290                 if (write) {
2291                         left -= proc_skip_spaces(&kbuf);
2292
2293                         if (!left)
2294                                 break;
2295                         err = proc_get_long(&kbuf, &left, &lval, &neg,
2296                                              proc_wspace_sep,
2297                                              sizeof(proc_wspace_sep), NULL);
2298                         if (err)
2299                                 break;
2300                         if (conv(&neg, &lval, i, 1, data)) {
2301                                 err = -EINVAL;
2302                                 break;
2303                         }
2304                 } else {
2305                         if (conv(&neg, &lval, i, 0, data)) {
2306                                 err = -EINVAL;
2307                                 break;
2308                         }
2309                         if (!first)
2310                                 err = proc_put_char(&buffer, &left, '\t');
2311                         if (err)
2312                                 break;
2313                         err = proc_put_long(&buffer, &left, lval, neg);
2314                         if (err)
2315                                 break;
2316                 }
2317         }
2318
2319         if (!write && !first && left && !err)
2320                 err = proc_put_char(&buffer, &left, '\n');
2321         if (write && !err && left)
2322                 left -= proc_skip_spaces(&kbuf);
2323 free:
2324         if (write) {
2325                 free_page(page);
2326                 if (first)
2327                         return err ? : -EINVAL;
2328         }
2329         *lenp -= left;
2330         *ppos += *lenp;
2331         return err;
2332 }
2333
2334 static int do_proc_dointvec(struct ctl_table *table, int write,
2335                   void __user *buffer, size_t *lenp, loff_t *ppos,
2336                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2337                               int write, void *data),
2338                   void *data)
2339 {
2340         return __do_proc_dointvec(table->data, table, write,
2341                         buffer, lenp, ppos, conv, data);
2342 }
2343
2344 /**
2345  * proc_dointvec - read a vector of integers
2346  * @table: the sysctl table
2347  * @write: %TRUE if this is a write to the sysctl file
2348  * @buffer: the user buffer
2349  * @lenp: the size of the user buffer
2350  * @ppos: file position
2351  *
2352  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2353  * values from/to the user buffer, treated as an ASCII string. 
2354  *
2355  * Returns 0 on success.
2356  */
2357 int proc_dointvec(struct ctl_table *table, int write,
2358                      void __user *buffer, size_t *lenp, loff_t *ppos)
2359 {
2360     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2361                             NULL,NULL);
2362 }
2363
2364 /*
2365  * Taint values can only be increased
2366  * This means we can safely use a temporary.
2367  */
2368 static int proc_taint(struct ctl_table *table, int write,
2369                                void __user *buffer, size_t *lenp, loff_t *ppos)
2370 {
2371         struct ctl_table t;
2372         unsigned long tmptaint = get_taint();
2373         int err;
2374
2375         if (write && !capable(CAP_SYS_ADMIN))
2376                 return -EPERM;
2377
2378         t = *table;
2379         t.data = &tmptaint;
2380         err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2381         if (err < 0)
2382                 return err;
2383
2384         if (write) {
2385                 /*
2386                  * Poor man's atomic or. Not worth adding a primitive
2387                  * to everyone's atomic.h for this
2388                  */
2389                 int i;
2390                 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2391                         if ((tmptaint >> i) & 1)
2392                                 add_taint(i);
2393                 }
2394         }
2395
2396         return err;
2397 }
2398
2399 #ifdef CONFIG_PRINTK
2400 static int proc_dmesg_restrict(struct ctl_table *table, int write,
2401                                 void __user *buffer, size_t *lenp, loff_t *ppos)
2402 {
2403         if (write && !capable(CAP_SYS_ADMIN))
2404                 return -EPERM;
2405
2406         return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2407 }
2408 #endif
2409
2410 struct do_proc_dointvec_minmax_conv_param {
2411         int *min;
2412         int *max;
2413 };
2414
2415 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2416                                         int *valp,
2417                                         int write, void *data)
2418 {
2419         struct do_proc_dointvec_minmax_conv_param *param = data;
2420         if (write) {
2421                 int val = *negp ? -*lvalp : *lvalp;
2422                 if ((param->min && *param->min > val) ||
2423                     (param->max && *param->max < val))
2424                         return -EINVAL;
2425                 *valp = val;
2426         } else {
2427                 int val = *valp;
2428                 if (val < 0) {
2429                         *negp = true;
2430                         *lvalp = (unsigned long)-val;
2431                 } else {
2432                         *negp = false;
2433                         *lvalp = (unsigned long)val;
2434                 }
2435         }
2436         return 0;
2437 }
2438
2439 /**
2440  * proc_dointvec_minmax - read a vector of integers with min/max values
2441  * @table: the sysctl table
2442  * @write: %TRUE if this is a write to the sysctl file
2443  * @buffer: the user buffer
2444  * @lenp: the size of the user buffer
2445  * @ppos: file position
2446  *
2447  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2448  * values from/to the user buffer, treated as an ASCII string.
2449  *
2450  * This routine will ensure the values are within the range specified by
2451  * table->extra1 (min) and table->extra2 (max).
2452  *
2453  * Returns 0 on success.
2454  */
2455 int proc_dointvec_minmax(struct ctl_table *table, int write,
2456                   void __user *buffer, size_t *lenp, loff_t *ppos)
2457 {
2458         struct do_proc_dointvec_minmax_conv_param param = {
2459                 .min = (int *) table->extra1,
2460                 .max = (int *) table->extra2,
2461         };
2462         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2463                                 do_proc_dointvec_minmax_conv, &param);
2464 }
2465
2466 /**
2467  * proc_dointvec_bool - read a vector of integers with 0/1 values
2468  * @table: the sysctl table
2469  * @write: %TRUE if this is a write to the sysctl file
2470  * @buffer: the user buffer
2471  * @lenp: the size of the user buffer
2472  * @ppos: file position
2473  *
2474  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2475  * values from/to the user buffer, treated as an ASCII string.
2476  *
2477  * This routine will ensure the values are either 0 or 1.
2478  *
2479  * Returns 0 on success.
2480  */
2481 int proc_dointvec_bool(struct ctl_table *table, int write,
2482                   void __user *buffer, size_t *lenp, loff_t *ppos)
2483 {
2484         struct do_proc_dointvec_minmax_conv_param param = {
2485                 .min = &zero,
2486                 .max = &one,
2487         };
2488         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2489                                 do_proc_dointvec_minmax_conv, &param);
2490 }
2491 EXPORT_SYMBOL(proc_dointvec_bool);
2492
2493 /**
2494  * proc_dointvec_unsigned - read a vector of integers with positive values
2495  * @table: the sysctl table
2496  * @write: %TRUE if this is a write to the sysctl file
2497  * @buffer: the user buffer
2498  * @lenp: the size of the user buffer
2499  * @ppos: file position
2500  *
2501  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2502  * values from/to the user buffer, treated as an ASCII string.
2503  *
2504  * This routine will ensure the values are positive.
2505  *
2506  * Returns 0 on success.
2507  */
2508 int proc_dointvec_unsigned(struct ctl_table *table, int write,
2509                   void __user *buffer, size_t *lenp, loff_t *ppos)
2510 {
2511         struct do_proc_dointvec_minmax_conv_param param = {
2512                 .min = &zero,
2513         };
2514         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2515                                 do_proc_dointvec_minmax_conv, &param);
2516 }
2517 EXPORT_SYMBOL(proc_dointvec_unsigned);
2518
2519 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2520                                      void __user *buffer,
2521                                      size_t *lenp, loff_t *ppos,
2522                                      unsigned long convmul,
2523                                      unsigned long convdiv)
2524 {
2525         unsigned long *i, *min, *max;
2526         int vleft, first = 1, err = 0;
2527         unsigned long page = 0;
2528         size_t left;
2529         char *kbuf;
2530
2531         if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2532                 *lenp = 0;
2533                 return 0;
2534         }
2535
2536         i = (unsigned long *) data;
2537         min = (unsigned long *) table->extra1;
2538         max = (unsigned long *) table->extra2;
2539         vleft = table->maxlen / sizeof(unsigned long);
2540         left = *lenp;
2541
2542         if (write) {
2543                 if (left > PAGE_SIZE - 1)
2544                         left = PAGE_SIZE - 1;
2545                 page = __get_free_page(GFP_TEMPORARY);
2546                 kbuf = (char *) page;
2547                 if (!kbuf)
2548                         return -ENOMEM;
2549                 if (copy_from_user(kbuf, buffer, left)) {
2550                         err = -EFAULT;
2551                         goto free;
2552                 }
2553                 kbuf[left] = 0;
2554         }
2555
2556         for (; left && vleft--; i++, first = 0) {
2557                 unsigned long val;
2558
2559                 if (write) {
2560                         bool neg;
2561
2562                         left -= proc_skip_spaces(&kbuf);
2563
2564                         err = proc_get_long(&kbuf, &left, &val, &neg,
2565                                              proc_wspace_sep,
2566                                              sizeof(proc_wspace_sep), NULL);
2567                         if (err)
2568                                 break;
2569                         if (neg)
2570                                 continue;
2571                         if ((min && val < *min) || (max && val > *max))
2572                                 continue;
2573                         *i = val;
2574                 } else {
2575                         val = convdiv * (*i) / convmul;
2576                         if (!first)
2577                                 err = proc_put_char(&buffer, &left, '\t');
2578                         err = proc_put_long(&buffer, &left, val, false);
2579                         if (err)
2580                                 break;
2581                 }
2582         }
2583
2584         if (!write && !first && left && !err)
2585                 err = proc_put_char(&buffer, &left, '\n');
2586         if (write && !err)
2587                 left -= proc_skip_spaces(&kbuf);
2588 free:
2589         if (write) {
2590                 free_page(page);
2591                 if (first)
2592                         return err ? : -EINVAL;
2593         }
2594         *lenp -= left;
2595         *ppos += *lenp;
2596         return err;
2597 }
2598
2599 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2600                                      void __user *buffer,
2601                                      size_t *lenp, loff_t *ppos,
2602                                      unsigned long convmul,
2603                                      unsigned long convdiv)
2604 {
2605         return __do_proc_doulongvec_minmax(table->data, table, write,
2606                         buffer, lenp, ppos, convmul, convdiv);
2607 }
2608
2609 /**
2610  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2611  * @table: the sysctl table
2612  * @write: %TRUE if this is a write to the sysctl file
2613  * @buffer: the user buffer
2614  * @lenp: the size of the user buffer
2615  * @ppos: file position
2616  *
2617  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2618  * values from/to the user buffer, treated as an ASCII string.
2619  *
2620  * This routine will ensure the values are within the range specified by
2621  * table->extra1 (min) and table->extra2 (max).
2622  *
2623  * Returns 0 on success.
2624  */
2625 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2626                            void __user *buffer, size_t *lenp, loff_t *ppos)
2627 {
2628     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2629 }
2630
2631 /**
2632  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2633  * @table: the sysctl table
2634  * @write: %TRUE if this is a write to the sysctl file
2635  * @buffer: the user buffer
2636  * @lenp: the size of the user buffer
2637  * @ppos: file position
2638  *
2639  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2640  * values from/to the user buffer, treated as an ASCII string. The values
2641  * are treated as milliseconds, and converted to jiffies when they are stored.
2642  *
2643  * This routine will ensure the values are within the range specified by
2644  * table->extra1 (min) and table->extra2 (max).
2645  *
2646  * Returns 0 on success.
2647  */
2648 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2649                                       void __user *buffer,
2650                                       size_t *lenp, loff_t *ppos)
2651 {
2652     return do_proc_doulongvec_minmax(table, write, buffer,
2653                                      lenp, ppos, HZ, 1000l);
2654 }
2655
2656
2657 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2658                                          int *valp,
2659                                          int write, void *data)
2660 {
2661         if (write) {
2662                 if (*lvalp > LONG_MAX / HZ)
2663                         return 1;
2664                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2665         } else {
2666                 int val = *valp;
2667                 unsigned long lval;
2668                 if (val < 0) {
2669                         *negp = true;
2670                         lval = (unsigned long)-val;
2671                 } else {
2672                         *negp = false;
2673                         lval = (unsigned long)val;
2674                 }
2675                 *lvalp = lval / HZ;
2676         }
2677         return 0;
2678 }
2679
2680 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2681                                                 int *valp,
2682                                                 int write, void *data)
2683 {
2684         if (write) {
2685                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2686                         return 1;
2687                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2688         } else {
2689                 int val = *valp;
2690                 unsigned long lval;
2691                 if (val < 0) {
2692                         *negp = true;
2693                         lval = (unsigned long)-val;
2694                 } else {
2695                         *negp = false;
2696                         lval = (unsigned long)val;
2697                 }
2698                 *lvalp = jiffies_to_clock_t(lval);
2699         }
2700         return 0;
2701 }
2702
2703 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2704                                             int *valp,
2705                                             int write, void *data)
2706 {
2707         if (write) {
2708                 *valp = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2709         } else {
2710                 int val = *valp;
2711                 unsigned long lval;
2712                 if (val < 0) {
2713                         *negp = true;
2714                         lval = (unsigned long)-val;
2715                 } else {
2716                         *negp = false;
2717                         lval = (unsigned long)val;
2718                 }
2719                 *lvalp = jiffies_to_msecs(lval);
2720         }
2721         return 0;
2722 }
2723
2724 /**
2725  * proc_dointvec_jiffies - read a vector of integers as seconds
2726  * @table: the sysctl table
2727  * @write: %TRUE if this is a write to the sysctl file
2728  * @buffer: the user buffer
2729  * @lenp: the size of the user buffer
2730  * @ppos: file position
2731  *
2732  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2733  * values from/to the user buffer, treated as an ASCII string. 
2734  * The values read are assumed to be in seconds, and are converted into
2735  * jiffies.
2736  *
2737  * Returns 0 on success.
2738  */
2739 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2740                           void __user *buffer, size_t *lenp, loff_t *ppos)
2741 {
2742     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2743                             do_proc_dointvec_jiffies_conv,NULL);
2744 }
2745
2746 /**
2747  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2748  * @table: the sysctl table
2749  * @write: %TRUE if this is a write to the sysctl file
2750  * @buffer: the user buffer
2751  * @lenp: the size of the user buffer
2752  * @ppos: pointer to the file position
2753  *
2754  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2755  * values from/to the user buffer, treated as an ASCII string. 
2756  * The values read are assumed to be in 1/USER_HZ seconds, and 
2757  * are converted into jiffies.
2758  *
2759  * Returns 0 on success.
2760  */
2761 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2762                                  void __user *buffer, size_t *lenp, loff_t *ppos)
2763 {
2764     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2765                             do_proc_dointvec_userhz_jiffies_conv,NULL);
2766 }
2767
2768 /**
2769  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2770  * @table: the sysctl table
2771  * @write: %TRUE if this is a write to the sysctl file
2772  * @buffer: the user buffer
2773  * @lenp: the size of the user buffer
2774  * @ppos: file position
2775  * @ppos: the current position in the file
2776  *
2777  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2778  * values from/to the user buffer, treated as an ASCII string. 
2779  * The values read are assumed to be in 1/1000 seconds, and 
2780  * are converted into jiffies.
2781  *
2782  * Returns 0 on success.
2783  */
2784 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2785                              void __user *buffer, size_t *lenp, loff_t *ppos)
2786 {
2787         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2788                                 do_proc_dointvec_ms_jiffies_conv, NULL);
2789 }
2790
2791 static int proc_do_cad_pid(struct ctl_table *table, int write,
2792                            void __user *buffer, size_t *lenp, loff_t *ppos)
2793 {
2794         struct pid *new_pid;
2795         pid_t tmp;
2796         int r;
2797
2798         tmp = pid_vnr(cad_pid);
2799
2800         r = __do_proc_dointvec(&tmp, table, write, buffer,
2801                                lenp, ppos, NULL, NULL);
2802         if (r || !write)
2803                 return r;
2804
2805         new_pid = find_get_pid(tmp);
2806         if (!new_pid)
2807                 return -ESRCH;
2808
2809         put_pid(xchg(&cad_pid, new_pid));
2810         return 0;
2811 }
2812
2813 /**
2814  * proc_do_large_bitmap - read/write from/to a large bitmap
2815  * @table: the sysctl table
2816  * @write: %TRUE if this is a write to the sysctl file
2817  * @buffer: the user buffer
2818  * @lenp: the size of the user buffer
2819  * @ppos: file position
2820  *
2821  * The bitmap is stored at table->data and the bitmap length (in bits)
2822  * in table->maxlen.
2823  *
2824  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2825  * large bitmaps may be represented in a compact manner. Writing into
2826  * the file will clear the bitmap then update it with the given input.
2827  *
2828  * Returns 0 on success.
2829  */
2830 int proc_do_large_bitmap(struct ctl_table *table, int write,
2831                          void __user *buffer, size_t *lenp, loff_t *ppos)
2832 {
2833         int err = 0;
2834         bool first = 1;
2835         size_t left = *lenp;
2836         unsigned long bitmap_len = table->maxlen;
2837         unsigned long *bitmap = (unsigned long *) table->data;
2838         unsigned long *tmp_bitmap = NULL;
2839         char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2840
2841         if (!bitmap_len || !left || (*ppos && !write)) {
2842                 *lenp = 0;
2843                 return 0;
2844         }
2845
2846         if (write) {
2847                 unsigned long page = 0;
2848                 char *kbuf;
2849
2850                 if (left > PAGE_SIZE - 1)
2851                         left = PAGE_SIZE - 1;
2852
2853                 page = __get_free_page(GFP_TEMPORARY);
2854                 kbuf = (char *) page;
2855                 if (!kbuf)
2856                         return -ENOMEM;
2857                 if (copy_from_user(kbuf, buffer, left)) {
2858                         free_page(page);
2859                         return -EFAULT;
2860                 }
2861                 kbuf[left] = 0;
2862
2863                 tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2864                                      GFP_KERNEL);
2865                 if (!tmp_bitmap) {
2866                         free_page(page);
2867                         return -ENOMEM;
2868                 }
2869                 proc_skip_char(&kbuf, &left, '\n');
2870                 while (!err && left) {
2871                         unsigned long val_a, val_b;
2872                         bool neg;
2873
2874                         err = proc_get_long(&kbuf, &left, &val_a, &neg, tr_a,
2875                                              sizeof(tr_a), &c);
2876                         if (err)
2877                                 break;
2878                         if (val_a >= bitmap_len || neg) {
2879                                 err = -EINVAL;
2880                                 break;
2881                         }
2882
2883                         val_b = val_a;
2884                         if (left) {
2885                                 kbuf++;
2886                                 left--;
2887                         }
2888
2889                         if (c == '-') {
2890                                 err = proc_get_long(&kbuf, &left, &val_b,
2891                                                      &neg, tr_b, sizeof(tr_b),
2892                                                      &c);
2893                                 if (err)
2894                                         break;
2895                                 if (val_b >= bitmap_len || neg ||
2896                                     val_a > val_b) {
2897                                         err = -EINVAL;
2898                                         break;
2899                                 }
2900                                 if (left) {
2901                                         kbuf++;
2902                                         left--;
2903                                 }
2904                         }
2905
2906                         while (val_a <= val_b)
2907                                 set_bit(val_a++, tmp_bitmap);
2908
2909                         first = 0;
2910                         proc_skip_char(&kbuf, &left, '\n');
2911                 }
2912                 free_page(page);
2913         } else {
2914                 unsigned long bit_a, bit_b = 0;
2915
2916                 while (left) {
2917                         bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2918                         if (bit_a >= bitmap_len)
2919                                 break;
2920                         bit_b = find_next_zero_bit(bitmap, bitmap_len,
2921                                                    bit_a + 1) - 1;
2922
2923                         if (!first) {
2924                                 err = proc_put_char(&buffer, &left, ',');
2925                                 if (err)
2926                                         break;
2927                         }
2928                         err = proc_put_long(&buffer, &left, bit_a, false);
2929                         if (err)
2930                                 break;
2931                         if (bit_a != bit_b) {
2932                                 err = proc_put_char(&buffer, &left, '-');
2933                                 if (err)
2934                                         break;
2935                                 err = proc_put_long(&buffer, &left, bit_b, false);
2936                                 if (err)
2937                                         break;
2938                         }
2939
2940                         first = 0; bit_b++;
2941                 }
2942                 if (!err)
2943                         err = proc_put_char(&buffer, &left, '\n');
2944         }
2945
2946         if (!err) {
2947                 if (write) {
2948                         if (*ppos)
2949                                 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2950                         else
2951                                 memcpy(bitmap, tmp_bitmap,
2952                                         BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long));
2953                 }
2954                 kfree(tmp_bitmap);
2955                 *lenp -= left;
2956                 *ppos += *lenp;
2957                 return 0;
2958         } else {
2959                 kfree(tmp_bitmap);
2960                 return err;
2961         }
2962 }
2963
2964 #else /* CONFIG_PROC_SYSCTL */
2965
2966 int proc_dostring(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(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_minmax(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_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_userhz_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_dointvec_ms_jiffies(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_minmax(struct ctl_table *table, int write,
3003                     void __user *buffer, size_t *lenp, loff_t *ppos)
3004 {
3005         return -ENOSYS;
3006 }
3007
3008 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3009                                       void __user *buffer,
3010                                       size_t *lenp, loff_t *ppos)
3011 {
3012     return -ENOSYS;
3013 }
3014
3015
3016 #endif /* CONFIG_PROC_SYSCTL */
3017
3018 /*
3019  * No sense putting this after each symbol definition, twice,
3020  * exception granted :-)
3021  */
3022 EXPORT_SYMBOL(proc_dointvec);
3023 EXPORT_SYMBOL(proc_dointvec_jiffies);
3024 EXPORT_SYMBOL(proc_dointvec_minmax);
3025 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3026 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3027 EXPORT_SYMBOL(proc_dostring);
3028 EXPORT_SYMBOL(proc_doulongvec_minmax);
3029 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3030 EXPORT_SYMBOL(register_sysctl_table);
3031 EXPORT_SYMBOL(register_sysctl_paths);
3032 EXPORT_SYMBOL(unregister_sysctl_table);