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