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