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