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