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