OSDN Git Service

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