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