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