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