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