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