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