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