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