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