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