xref: /openbmc/linux/kernel/sysctl.c (revision 3805e6a1)
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 static int one_thousand = 1000;
130 #ifdef CONFIG_PRINTK
131 static int ten_thousand = 10000;
132 #endif
133 #ifdef CONFIG_PERF_EVENTS
134 static int six_hundred_forty_kb = 640 * 1024;
135 #endif
136 
137 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
138 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
139 
140 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
141 static int maxolduid = 65535;
142 static int minolduid;
143 
144 static int ngroups_max = NGROUPS_MAX;
145 static const int cap_last_cap = CAP_LAST_CAP;
146 
147 /*this is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs */
148 #ifdef CONFIG_DETECT_HUNG_TASK
149 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
150 #endif
151 
152 #ifdef CONFIG_INOTIFY_USER
153 #include <linux/inotify.h>
154 #endif
155 #ifdef CONFIG_SPARC
156 #endif
157 
158 #ifdef __hppa__
159 extern int pwrsw_enabled;
160 #endif
161 
162 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
163 extern int unaligned_enabled;
164 #endif
165 
166 #ifdef CONFIG_IA64
167 extern int unaligned_dump_stack;
168 #endif
169 
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
171 extern int no_unaligned_warning;
172 #endif
173 
174 #ifdef CONFIG_PROC_SYSCTL
175 
176 #define SYSCTL_WRITES_LEGACY	-1
177 #define SYSCTL_WRITES_WARN	 0
178 #define SYSCTL_WRITES_STRICT	 1
179 
180 static int sysctl_writes_strict = SYSCTL_WRITES_STRICT;
181 
182 static int proc_do_cad_pid(struct ctl_table *table, int write,
183 		  void __user *buffer, size_t *lenp, loff_t *ppos);
184 static int proc_taint(struct ctl_table *table, int write,
185 			       void __user *buffer, size_t *lenp, loff_t *ppos);
186 #endif
187 
188 #ifdef CONFIG_PRINTK
189 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
190 				void __user *buffer, size_t *lenp, loff_t *ppos);
191 #endif
192 
193 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
194 		void __user *buffer, size_t *lenp, loff_t *ppos);
195 #ifdef CONFIG_COREDUMP
196 static int proc_dostring_coredump(struct ctl_table *table, int write,
197 		void __user *buffer, size_t *lenp, loff_t *ppos);
198 #endif
199 
200 #ifdef CONFIG_MAGIC_SYSRQ
201 /* Note: sysrq code uses it's own private copy */
202 static int __sysrq_enabled = CONFIG_MAGIC_SYSRQ_DEFAULT_ENABLE;
203 
204 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
205 				void __user *buffer, size_t *lenp,
206 				loff_t *ppos)
207 {
208 	int error;
209 
210 	error = proc_dointvec(table, write, buffer, lenp, ppos);
211 	if (error)
212 		return error;
213 
214 	if (write)
215 		sysrq_toggle_support(__sysrq_enabled);
216 
217 	return 0;
218 }
219 
220 #endif
221 
222 static struct ctl_table kern_table[];
223 static struct ctl_table vm_table[];
224 static struct ctl_table fs_table[];
225 static struct ctl_table debug_table[];
226 static struct ctl_table dev_table[];
227 extern struct ctl_table random_table[];
228 #ifdef CONFIG_EPOLL
229 extern struct ctl_table epoll_table[];
230 #endif
231 
232 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
233 int sysctl_legacy_va_layout;
234 #endif
235 
236 /* The default sysctl tables: */
237 
238 static struct ctl_table sysctl_base_table[] = {
239 	{
240 		.procname	= "kernel",
241 		.mode		= 0555,
242 		.child		= kern_table,
243 	},
244 	{
245 		.procname	= "vm",
246 		.mode		= 0555,
247 		.child		= vm_table,
248 	},
249 	{
250 		.procname	= "fs",
251 		.mode		= 0555,
252 		.child		= fs_table,
253 	},
254 	{
255 		.procname	= "debug",
256 		.mode		= 0555,
257 		.child		= debug_table,
258 	},
259 	{
260 		.procname	= "dev",
261 		.mode		= 0555,
262 		.child		= dev_table,
263 	},
264 	{ }
265 };
266 
267 #ifdef CONFIG_SCHED_DEBUG
268 static int min_sched_granularity_ns = 100000;		/* 100 usecs */
269 static int max_sched_granularity_ns = NSEC_PER_SEC;	/* 1 second */
270 static int min_wakeup_granularity_ns;			/* 0 usecs */
271 static int max_wakeup_granularity_ns = NSEC_PER_SEC;	/* 1 second */
272 #ifdef CONFIG_SMP
273 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
274 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
275 #endif /* CONFIG_SMP */
276 #endif /* CONFIG_SCHED_DEBUG */
277 
278 #ifdef CONFIG_COMPACTION
279 static int min_extfrag_threshold;
280 static int max_extfrag_threshold = 1000;
281 #endif
282 
283 static struct ctl_table kern_table[] = {
284 	{
285 		.procname	= "sched_child_runs_first",
286 		.data		= &sysctl_sched_child_runs_first,
287 		.maxlen		= sizeof(unsigned int),
288 		.mode		= 0644,
289 		.proc_handler	= proc_dointvec,
290 	},
291 #ifdef CONFIG_SCHED_DEBUG
292 	{
293 		.procname	= "sched_min_granularity_ns",
294 		.data		= &sysctl_sched_min_granularity,
295 		.maxlen		= sizeof(unsigned int),
296 		.mode		= 0644,
297 		.proc_handler	= sched_proc_update_handler,
298 		.extra1		= &min_sched_granularity_ns,
299 		.extra2		= &max_sched_granularity_ns,
300 	},
301 	{
302 		.procname	= "sched_latency_ns",
303 		.data		= &sysctl_sched_latency,
304 		.maxlen		= sizeof(unsigned int),
305 		.mode		= 0644,
306 		.proc_handler	= sched_proc_update_handler,
307 		.extra1		= &min_sched_granularity_ns,
308 		.extra2		= &max_sched_granularity_ns,
309 	},
310 	{
311 		.procname	= "sched_wakeup_granularity_ns",
312 		.data		= &sysctl_sched_wakeup_granularity,
313 		.maxlen		= sizeof(unsigned int),
314 		.mode		= 0644,
315 		.proc_handler	= sched_proc_update_handler,
316 		.extra1		= &min_wakeup_granularity_ns,
317 		.extra2		= &max_wakeup_granularity_ns,
318 	},
319 #ifdef CONFIG_SMP
320 	{
321 		.procname	= "sched_tunable_scaling",
322 		.data		= &sysctl_sched_tunable_scaling,
323 		.maxlen		= sizeof(enum sched_tunable_scaling),
324 		.mode		= 0644,
325 		.proc_handler	= sched_proc_update_handler,
326 		.extra1		= &min_sched_tunable_scaling,
327 		.extra2		= &max_sched_tunable_scaling,
328 	},
329 	{
330 		.procname	= "sched_migration_cost_ns",
331 		.data		= &sysctl_sched_migration_cost,
332 		.maxlen		= sizeof(unsigned int),
333 		.mode		= 0644,
334 		.proc_handler	= proc_dointvec,
335 	},
336 	{
337 		.procname	= "sched_nr_migrate",
338 		.data		= &sysctl_sched_nr_migrate,
339 		.maxlen		= sizeof(unsigned int),
340 		.mode		= 0644,
341 		.proc_handler	= proc_dointvec,
342 	},
343 	{
344 		.procname	= "sched_time_avg_ms",
345 		.data		= &sysctl_sched_time_avg,
346 		.maxlen		= sizeof(unsigned int),
347 		.mode		= 0644,
348 		.proc_handler	= proc_dointvec,
349 	},
350 	{
351 		.procname	= "sched_shares_window_ns",
352 		.data		= &sysctl_sched_shares_window,
353 		.maxlen		= sizeof(unsigned int),
354 		.mode		= 0644,
355 		.proc_handler	= proc_dointvec,
356 	},
357 #ifdef CONFIG_SCHEDSTATS
358 	{
359 		.procname	= "sched_schedstats",
360 		.data		= NULL,
361 		.maxlen		= sizeof(unsigned int),
362 		.mode		= 0644,
363 		.proc_handler	= sysctl_schedstats,
364 		.extra1		= &zero,
365 		.extra2		= &one,
366 	},
367 #endif /* CONFIG_SCHEDSTATS */
368 #endif /* CONFIG_SMP */
369 #ifdef CONFIG_NUMA_BALANCING
370 	{
371 		.procname	= "numa_balancing_scan_delay_ms",
372 		.data		= &sysctl_numa_balancing_scan_delay,
373 		.maxlen		= sizeof(unsigned int),
374 		.mode		= 0644,
375 		.proc_handler	= proc_dointvec,
376 	},
377 	{
378 		.procname	= "numa_balancing_scan_period_min_ms",
379 		.data		= &sysctl_numa_balancing_scan_period_min,
380 		.maxlen		= sizeof(unsigned int),
381 		.mode		= 0644,
382 		.proc_handler	= proc_dointvec,
383 	},
384 	{
385 		.procname	= "numa_balancing_scan_period_max_ms",
386 		.data		= &sysctl_numa_balancing_scan_period_max,
387 		.maxlen		= sizeof(unsigned int),
388 		.mode		= 0644,
389 		.proc_handler	= proc_dointvec,
390 	},
391 	{
392 		.procname	= "numa_balancing_scan_size_mb",
393 		.data		= &sysctl_numa_balancing_scan_size,
394 		.maxlen		= sizeof(unsigned int),
395 		.mode		= 0644,
396 		.proc_handler	= proc_dointvec_minmax,
397 		.extra1		= &one,
398 	},
399 	{
400 		.procname	= "numa_balancing",
401 		.data		= NULL, /* filled in by handler */
402 		.maxlen		= sizeof(unsigned int),
403 		.mode		= 0644,
404 		.proc_handler	= sysctl_numa_balancing,
405 		.extra1		= &zero,
406 		.extra2		= &one,
407 	},
408 #endif /* CONFIG_NUMA_BALANCING */
409 #endif /* CONFIG_SCHED_DEBUG */
410 	{
411 		.procname	= "sched_rt_period_us",
412 		.data		= &sysctl_sched_rt_period,
413 		.maxlen		= sizeof(unsigned int),
414 		.mode		= 0644,
415 		.proc_handler	= sched_rt_handler,
416 	},
417 	{
418 		.procname	= "sched_rt_runtime_us",
419 		.data		= &sysctl_sched_rt_runtime,
420 		.maxlen		= sizeof(int),
421 		.mode		= 0644,
422 		.proc_handler	= sched_rt_handler,
423 	},
424 	{
425 		.procname	= "sched_rr_timeslice_ms",
426 		.data		= &sched_rr_timeslice,
427 		.maxlen		= sizeof(int),
428 		.mode		= 0644,
429 		.proc_handler	= sched_rr_handler,
430 	},
431 #ifdef CONFIG_SCHED_AUTOGROUP
432 	{
433 		.procname	= "sched_autogroup_enabled",
434 		.data		= &sysctl_sched_autogroup_enabled,
435 		.maxlen		= sizeof(unsigned int),
436 		.mode		= 0644,
437 		.proc_handler	= proc_dointvec_minmax,
438 		.extra1		= &zero,
439 		.extra2		= &one,
440 	},
441 #endif
442 #ifdef CONFIG_CFS_BANDWIDTH
443 	{
444 		.procname	= "sched_cfs_bandwidth_slice_us",
445 		.data		= &sysctl_sched_cfs_bandwidth_slice,
446 		.maxlen		= sizeof(unsigned int),
447 		.mode		= 0644,
448 		.proc_handler	= proc_dointvec_minmax,
449 		.extra1		= &one,
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	= sysctl_latencytop,
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 	{
1151 		.procname	= "perf_event_max_stack",
1152 		.data		= &sysctl_perf_event_max_stack,
1153 		.maxlen		= sizeof(sysctl_perf_event_max_stack),
1154 		.mode		= 0644,
1155 		.proc_handler	= perf_event_max_stack_handler,
1156 		.extra1		= &zero,
1157 		.extra2		= &six_hundred_forty_kb,
1158 	},
1159 	{
1160 		.procname	= "perf_event_max_contexts_per_stack",
1161 		.data		= &sysctl_perf_event_max_contexts_per_stack,
1162 		.maxlen		= sizeof(sysctl_perf_event_max_contexts_per_stack),
1163 		.mode		= 0644,
1164 		.proc_handler	= perf_event_max_stack_handler,
1165 		.extra1		= &zero,
1166 		.extra2		= &one_thousand,
1167 	},
1168 #endif
1169 #ifdef CONFIG_KMEMCHECK
1170 	{
1171 		.procname	= "kmemcheck",
1172 		.data		= &kmemcheck_enabled,
1173 		.maxlen		= sizeof(int),
1174 		.mode		= 0644,
1175 		.proc_handler	= proc_dointvec,
1176 	},
1177 #endif
1178 	{
1179 		.procname	= "panic_on_warn",
1180 		.data		= &panic_on_warn,
1181 		.maxlen		= sizeof(int),
1182 		.mode		= 0644,
1183 		.proc_handler	= proc_dointvec_minmax,
1184 		.extra1		= &zero,
1185 		.extra2		= &one,
1186 	},
1187 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1188 	{
1189 		.procname	= "timer_migration",
1190 		.data		= &sysctl_timer_migration,
1191 		.maxlen		= sizeof(unsigned int),
1192 		.mode		= 0644,
1193 		.proc_handler	= timer_migration_handler,
1194 	},
1195 #endif
1196 #ifdef CONFIG_BPF_SYSCALL
1197 	{
1198 		.procname	= "unprivileged_bpf_disabled",
1199 		.data		= &sysctl_unprivileged_bpf_disabled,
1200 		.maxlen		= sizeof(sysctl_unprivileged_bpf_disabled),
1201 		.mode		= 0644,
1202 		/* only handle a transition from default "0" to "1" */
1203 		.proc_handler	= proc_dointvec_minmax,
1204 		.extra1		= &one,
1205 		.extra2		= &one,
1206 	},
1207 #endif
1208 	{ }
1209 };
1210 
1211 static struct ctl_table vm_table[] = {
1212 	{
1213 		.procname	= "overcommit_memory",
1214 		.data		= &sysctl_overcommit_memory,
1215 		.maxlen		= sizeof(sysctl_overcommit_memory),
1216 		.mode		= 0644,
1217 		.proc_handler	= proc_dointvec_minmax,
1218 		.extra1		= &zero,
1219 		.extra2		= &two,
1220 	},
1221 	{
1222 		.procname	= "panic_on_oom",
1223 		.data		= &sysctl_panic_on_oom,
1224 		.maxlen		= sizeof(sysctl_panic_on_oom),
1225 		.mode		= 0644,
1226 		.proc_handler	= proc_dointvec_minmax,
1227 		.extra1		= &zero,
1228 		.extra2		= &two,
1229 	},
1230 	{
1231 		.procname	= "oom_kill_allocating_task",
1232 		.data		= &sysctl_oom_kill_allocating_task,
1233 		.maxlen		= sizeof(sysctl_oom_kill_allocating_task),
1234 		.mode		= 0644,
1235 		.proc_handler	= proc_dointvec,
1236 	},
1237 	{
1238 		.procname	= "oom_dump_tasks",
1239 		.data		= &sysctl_oom_dump_tasks,
1240 		.maxlen		= sizeof(sysctl_oom_dump_tasks),
1241 		.mode		= 0644,
1242 		.proc_handler	= proc_dointvec,
1243 	},
1244 	{
1245 		.procname	= "overcommit_ratio",
1246 		.data		= &sysctl_overcommit_ratio,
1247 		.maxlen		= sizeof(sysctl_overcommit_ratio),
1248 		.mode		= 0644,
1249 		.proc_handler	= overcommit_ratio_handler,
1250 	},
1251 	{
1252 		.procname	= "overcommit_kbytes",
1253 		.data		= &sysctl_overcommit_kbytes,
1254 		.maxlen		= sizeof(sysctl_overcommit_kbytes),
1255 		.mode		= 0644,
1256 		.proc_handler	= overcommit_kbytes_handler,
1257 	},
1258 	{
1259 		.procname	= "page-cluster",
1260 		.data		= &page_cluster,
1261 		.maxlen		= sizeof(int),
1262 		.mode		= 0644,
1263 		.proc_handler	= proc_dointvec_minmax,
1264 		.extra1		= &zero,
1265 	},
1266 	{
1267 		.procname	= "dirty_background_ratio",
1268 		.data		= &dirty_background_ratio,
1269 		.maxlen		= sizeof(dirty_background_ratio),
1270 		.mode		= 0644,
1271 		.proc_handler	= dirty_background_ratio_handler,
1272 		.extra1		= &zero,
1273 		.extra2		= &one_hundred,
1274 	},
1275 	{
1276 		.procname	= "dirty_background_bytes",
1277 		.data		= &dirty_background_bytes,
1278 		.maxlen		= sizeof(dirty_background_bytes),
1279 		.mode		= 0644,
1280 		.proc_handler	= dirty_background_bytes_handler,
1281 		.extra1		= &one_ul,
1282 	},
1283 	{
1284 		.procname	= "dirty_ratio",
1285 		.data		= &vm_dirty_ratio,
1286 		.maxlen		= sizeof(vm_dirty_ratio),
1287 		.mode		= 0644,
1288 		.proc_handler	= dirty_ratio_handler,
1289 		.extra1		= &zero,
1290 		.extra2		= &one_hundred,
1291 	},
1292 	{
1293 		.procname	= "dirty_bytes",
1294 		.data		= &vm_dirty_bytes,
1295 		.maxlen		= sizeof(vm_dirty_bytes),
1296 		.mode		= 0644,
1297 		.proc_handler	= dirty_bytes_handler,
1298 		.extra1		= &dirty_bytes_min,
1299 	},
1300 	{
1301 		.procname	= "dirty_writeback_centisecs",
1302 		.data		= &dirty_writeback_interval,
1303 		.maxlen		= sizeof(dirty_writeback_interval),
1304 		.mode		= 0644,
1305 		.proc_handler	= dirty_writeback_centisecs_handler,
1306 	},
1307 	{
1308 		.procname	= "dirty_expire_centisecs",
1309 		.data		= &dirty_expire_interval,
1310 		.maxlen		= sizeof(dirty_expire_interval),
1311 		.mode		= 0644,
1312 		.proc_handler	= proc_dointvec_minmax,
1313 		.extra1		= &zero,
1314 	},
1315 	{
1316 		.procname	= "dirtytime_expire_seconds",
1317 		.data		= &dirtytime_expire_interval,
1318 		.maxlen		= sizeof(dirty_expire_interval),
1319 		.mode		= 0644,
1320 		.proc_handler	= dirtytime_interval_handler,
1321 		.extra1		= &zero,
1322 	},
1323 	{
1324 		.procname       = "nr_pdflush_threads",
1325 		.mode           = 0444 /* read-only */,
1326 		.proc_handler   = pdflush_proc_obsolete,
1327 	},
1328 	{
1329 		.procname	= "swappiness",
1330 		.data		= &vm_swappiness,
1331 		.maxlen		= sizeof(vm_swappiness),
1332 		.mode		= 0644,
1333 		.proc_handler	= proc_dointvec_minmax,
1334 		.extra1		= &zero,
1335 		.extra2		= &one_hundred,
1336 	},
1337 #ifdef CONFIG_HUGETLB_PAGE
1338 	{
1339 		.procname	= "nr_hugepages",
1340 		.data		= NULL,
1341 		.maxlen		= sizeof(unsigned long),
1342 		.mode		= 0644,
1343 		.proc_handler	= hugetlb_sysctl_handler,
1344 	},
1345 #ifdef CONFIG_NUMA
1346 	{
1347 		.procname       = "nr_hugepages_mempolicy",
1348 		.data           = NULL,
1349 		.maxlen         = sizeof(unsigned long),
1350 		.mode           = 0644,
1351 		.proc_handler   = &hugetlb_mempolicy_sysctl_handler,
1352 	},
1353 #endif
1354 	 {
1355 		.procname	= "hugetlb_shm_group",
1356 		.data		= &sysctl_hugetlb_shm_group,
1357 		.maxlen		= sizeof(gid_t),
1358 		.mode		= 0644,
1359 		.proc_handler	= proc_dointvec,
1360 	 },
1361 	 {
1362 		.procname	= "hugepages_treat_as_movable",
1363 		.data		= &hugepages_treat_as_movable,
1364 		.maxlen		= sizeof(int),
1365 		.mode		= 0644,
1366 		.proc_handler	= proc_dointvec,
1367 	},
1368 	{
1369 		.procname	= "nr_overcommit_hugepages",
1370 		.data		= NULL,
1371 		.maxlen		= sizeof(unsigned long),
1372 		.mode		= 0644,
1373 		.proc_handler	= hugetlb_overcommit_handler,
1374 	},
1375 #endif
1376 	{
1377 		.procname	= "lowmem_reserve_ratio",
1378 		.data		= &sysctl_lowmem_reserve_ratio,
1379 		.maxlen		= sizeof(sysctl_lowmem_reserve_ratio),
1380 		.mode		= 0644,
1381 		.proc_handler	= lowmem_reserve_ratio_sysctl_handler,
1382 	},
1383 	{
1384 		.procname	= "drop_caches",
1385 		.data		= &sysctl_drop_caches,
1386 		.maxlen		= sizeof(int),
1387 		.mode		= 0644,
1388 		.proc_handler	= drop_caches_sysctl_handler,
1389 		.extra1		= &one,
1390 		.extra2		= &four,
1391 	},
1392 #ifdef CONFIG_COMPACTION
1393 	{
1394 		.procname	= "compact_memory",
1395 		.data		= &sysctl_compact_memory,
1396 		.maxlen		= sizeof(int),
1397 		.mode		= 0200,
1398 		.proc_handler	= sysctl_compaction_handler,
1399 	},
1400 	{
1401 		.procname	= "extfrag_threshold",
1402 		.data		= &sysctl_extfrag_threshold,
1403 		.maxlen		= sizeof(int),
1404 		.mode		= 0644,
1405 		.proc_handler	= sysctl_extfrag_handler,
1406 		.extra1		= &min_extfrag_threshold,
1407 		.extra2		= &max_extfrag_threshold,
1408 	},
1409 	{
1410 		.procname	= "compact_unevictable_allowed",
1411 		.data		= &sysctl_compact_unevictable_allowed,
1412 		.maxlen		= sizeof(int),
1413 		.mode		= 0644,
1414 		.proc_handler	= proc_dointvec,
1415 		.extra1		= &zero,
1416 		.extra2		= &one,
1417 	},
1418 
1419 #endif /* CONFIG_COMPACTION */
1420 	{
1421 		.procname	= "min_free_kbytes",
1422 		.data		= &min_free_kbytes,
1423 		.maxlen		= sizeof(min_free_kbytes),
1424 		.mode		= 0644,
1425 		.proc_handler	= min_free_kbytes_sysctl_handler,
1426 		.extra1		= &zero,
1427 	},
1428 	{
1429 		.procname	= "watermark_scale_factor",
1430 		.data		= &watermark_scale_factor,
1431 		.maxlen		= sizeof(watermark_scale_factor),
1432 		.mode		= 0644,
1433 		.proc_handler	= watermark_scale_factor_sysctl_handler,
1434 		.extra1		= &one,
1435 		.extra2		= &one_thousand,
1436 	},
1437 	{
1438 		.procname	= "percpu_pagelist_fraction",
1439 		.data		= &percpu_pagelist_fraction,
1440 		.maxlen		= sizeof(percpu_pagelist_fraction),
1441 		.mode		= 0644,
1442 		.proc_handler	= percpu_pagelist_fraction_sysctl_handler,
1443 		.extra1		= &zero,
1444 	},
1445 #ifdef CONFIG_MMU
1446 	{
1447 		.procname	= "max_map_count",
1448 		.data		= &sysctl_max_map_count,
1449 		.maxlen		= sizeof(sysctl_max_map_count),
1450 		.mode		= 0644,
1451 		.proc_handler	= proc_dointvec_minmax,
1452 		.extra1		= &zero,
1453 	},
1454 #else
1455 	{
1456 		.procname	= "nr_trim_pages",
1457 		.data		= &sysctl_nr_trim_pages,
1458 		.maxlen		= sizeof(sysctl_nr_trim_pages),
1459 		.mode		= 0644,
1460 		.proc_handler	= proc_dointvec_minmax,
1461 		.extra1		= &zero,
1462 	},
1463 #endif
1464 	{
1465 		.procname	= "laptop_mode",
1466 		.data		= &laptop_mode,
1467 		.maxlen		= sizeof(laptop_mode),
1468 		.mode		= 0644,
1469 		.proc_handler	= proc_dointvec_jiffies,
1470 	},
1471 	{
1472 		.procname	= "block_dump",
1473 		.data		= &block_dump,
1474 		.maxlen		= sizeof(block_dump),
1475 		.mode		= 0644,
1476 		.proc_handler	= proc_dointvec,
1477 		.extra1		= &zero,
1478 	},
1479 	{
1480 		.procname	= "vfs_cache_pressure",
1481 		.data		= &sysctl_vfs_cache_pressure,
1482 		.maxlen		= sizeof(sysctl_vfs_cache_pressure),
1483 		.mode		= 0644,
1484 		.proc_handler	= proc_dointvec,
1485 		.extra1		= &zero,
1486 	},
1487 #ifdef HAVE_ARCH_PICK_MMAP_LAYOUT
1488 	{
1489 		.procname	= "legacy_va_layout",
1490 		.data		= &sysctl_legacy_va_layout,
1491 		.maxlen		= sizeof(sysctl_legacy_va_layout),
1492 		.mode		= 0644,
1493 		.proc_handler	= proc_dointvec,
1494 		.extra1		= &zero,
1495 	},
1496 #endif
1497 #ifdef CONFIG_NUMA
1498 	{
1499 		.procname	= "zone_reclaim_mode",
1500 		.data		= &zone_reclaim_mode,
1501 		.maxlen		= sizeof(zone_reclaim_mode),
1502 		.mode		= 0644,
1503 		.proc_handler	= proc_dointvec,
1504 		.extra1		= &zero,
1505 	},
1506 	{
1507 		.procname	= "min_unmapped_ratio",
1508 		.data		= &sysctl_min_unmapped_ratio,
1509 		.maxlen		= sizeof(sysctl_min_unmapped_ratio),
1510 		.mode		= 0644,
1511 		.proc_handler	= sysctl_min_unmapped_ratio_sysctl_handler,
1512 		.extra1		= &zero,
1513 		.extra2		= &one_hundred,
1514 	},
1515 	{
1516 		.procname	= "min_slab_ratio",
1517 		.data		= &sysctl_min_slab_ratio,
1518 		.maxlen		= sizeof(sysctl_min_slab_ratio),
1519 		.mode		= 0644,
1520 		.proc_handler	= sysctl_min_slab_ratio_sysctl_handler,
1521 		.extra1		= &zero,
1522 		.extra2		= &one_hundred,
1523 	},
1524 #endif
1525 #ifdef CONFIG_SMP
1526 	{
1527 		.procname	= "stat_interval",
1528 		.data		= &sysctl_stat_interval,
1529 		.maxlen		= sizeof(sysctl_stat_interval),
1530 		.mode		= 0644,
1531 		.proc_handler	= proc_dointvec_jiffies,
1532 	},
1533 	{
1534 		.procname	= "stat_refresh",
1535 		.data		= NULL,
1536 		.maxlen		= 0,
1537 		.mode		= 0600,
1538 		.proc_handler	= vmstat_refresh,
1539 	},
1540 #endif
1541 #ifdef CONFIG_MMU
1542 	{
1543 		.procname	= "mmap_min_addr",
1544 		.data		= &dac_mmap_min_addr,
1545 		.maxlen		= sizeof(unsigned long),
1546 		.mode		= 0644,
1547 		.proc_handler	= mmap_min_addr_handler,
1548 	},
1549 #endif
1550 #ifdef CONFIG_NUMA
1551 	{
1552 		.procname	= "numa_zonelist_order",
1553 		.data		= &numa_zonelist_order,
1554 		.maxlen		= NUMA_ZONELIST_ORDER_LEN,
1555 		.mode		= 0644,
1556 		.proc_handler	= numa_zonelist_order_handler,
1557 	},
1558 #endif
1559 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1560    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1561 	{
1562 		.procname	= "vdso_enabled",
1563 #ifdef CONFIG_X86_32
1564 		.data		= &vdso32_enabled,
1565 		.maxlen		= sizeof(vdso32_enabled),
1566 #else
1567 		.data		= &vdso_enabled,
1568 		.maxlen		= sizeof(vdso_enabled),
1569 #endif
1570 		.mode		= 0644,
1571 		.proc_handler	= proc_dointvec,
1572 		.extra1		= &zero,
1573 	},
1574 #endif
1575 #ifdef CONFIG_HIGHMEM
1576 	{
1577 		.procname	= "highmem_is_dirtyable",
1578 		.data		= &vm_highmem_is_dirtyable,
1579 		.maxlen		= sizeof(vm_highmem_is_dirtyable),
1580 		.mode		= 0644,
1581 		.proc_handler	= proc_dointvec_minmax,
1582 		.extra1		= &zero,
1583 		.extra2		= &one,
1584 	},
1585 #endif
1586 #ifdef CONFIG_MEMORY_FAILURE
1587 	{
1588 		.procname	= "memory_failure_early_kill",
1589 		.data		= &sysctl_memory_failure_early_kill,
1590 		.maxlen		= sizeof(sysctl_memory_failure_early_kill),
1591 		.mode		= 0644,
1592 		.proc_handler	= proc_dointvec_minmax,
1593 		.extra1		= &zero,
1594 		.extra2		= &one,
1595 	},
1596 	{
1597 		.procname	= "memory_failure_recovery",
1598 		.data		= &sysctl_memory_failure_recovery,
1599 		.maxlen		= sizeof(sysctl_memory_failure_recovery),
1600 		.mode		= 0644,
1601 		.proc_handler	= proc_dointvec_minmax,
1602 		.extra1		= &zero,
1603 		.extra2		= &one,
1604 	},
1605 #endif
1606 	{
1607 		.procname	= "user_reserve_kbytes",
1608 		.data		= &sysctl_user_reserve_kbytes,
1609 		.maxlen		= sizeof(sysctl_user_reserve_kbytes),
1610 		.mode		= 0644,
1611 		.proc_handler	= proc_doulongvec_minmax,
1612 	},
1613 	{
1614 		.procname	= "admin_reserve_kbytes",
1615 		.data		= &sysctl_admin_reserve_kbytes,
1616 		.maxlen		= sizeof(sysctl_admin_reserve_kbytes),
1617 		.mode		= 0644,
1618 		.proc_handler	= proc_doulongvec_minmax,
1619 	},
1620 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1621 	{
1622 		.procname	= "mmap_rnd_bits",
1623 		.data		= &mmap_rnd_bits,
1624 		.maxlen		= sizeof(mmap_rnd_bits),
1625 		.mode		= 0600,
1626 		.proc_handler	= proc_dointvec_minmax,
1627 		.extra1		= (void *)&mmap_rnd_bits_min,
1628 		.extra2		= (void *)&mmap_rnd_bits_max,
1629 	},
1630 #endif
1631 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1632 	{
1633 		.procname	= "mmap_rnd_compat_bits",
1634 		.data		= &mmap_rnd_compat_bits,
1635 		.maxlen		= sizeof(mmap_rnd_compat_bits),
1636 		.mode		= 0600,
1637 		.proc_handler	= proc_dointvec_minmax,
1638 		.extra1		= (void *)&mmap_rnd_compat_bits_min,
1639 		.extra2		= (void *)&mmap_rnd_compat_bits_max,
1640 	},
1641 #endif
1642 	{ }
1643 };
1644 
1645 static struct ctl_table fs_table[] = {
1646 	{
1647 		.procname	= "inode-nr",
1648 		.data		= &inodes_stat,
1649 		.maxlen		= 2*sizeof(long),
1650 		.mode		= 0444,
1651 		.proc_handler	= proc_nr_inodes,
1652 	},
1653 	{
1654 		.procname	= "inode-state",
1655 		.data		= &inodes_stat,
1656 		.maxlen		= 7*sizeof(long),
1657 		.mode		= 0444,
1658 		.proc_handler	= proc_nr_inodes,
1659 	},
1660 	{
1661 		.procname	= "file-nr",
1662 		.data		= &files_stat,
1663 		.maxlen		= sizeof(files_stat),
1664 		.mode		= 0444,
1665 		.proc_handler	= proc_nr_files,
1666 	},
1667 	{
1668 		.procname	= "file-max",
1669 		.data		= &files_stat.max_files,
1670 		.maxlen		= sizeof(files_stat.max_files),
1671 		.mode		= 0644,
1672 		.proc_handler	= proc_doulongvec_minmax,
1673 	},
1674 	{
1675 		.procname	= "nr_open",
1676 		.data		= &sysctl_nr_open,
1677 		.maxlen		= sizeof(int),
1678 		.mode		= 0644,
1679 		.proc_handler	= proc_dointvec_minmax,
1680 		.extra1		= &sysctl_nr_open_min,
1681 		.extra2		= &sysctl_nr_open_max,
1682 	},
1683 	{
1684 		.procname	= "dentry-state",
1685 		.data		= &dentry_stat,
1686 		.maxlen		= 6*sizeof(long),
1687 		.mode		= 0444,
1688 		.proc_handler	= proc_nr_dentry,
1689 	},
1690 	{
1691 		.procname	= "overflowuid",
1692 		.data		= &fs_overflowuid,
1693 		.maxlen		= sizeof(int),
1694 		.mode		= 0644,
1695 		.proc_handler	= proc_dointvec_minmax,
1696 		.extra1		= &minolduid,
1697 		.extra2		= &maxolduid,
1698 	},
1699 	{
1700 		.procname	= "overflowgid",
1701 		.data		= &fs_overflowgid,
1702 		.maxlen		= sizeof(int),
1703 		.mode		= 0644,
1704 		.proc_handler	= proc_dointvec_minmax,
1705 		.extra1		= &minolduid,
1706 		.extra2		= &maxolduid,
1707 	},
1708 #ifdef CONFIG_FILE_LOCKING
1709 	{
1710 		.procname	= "leases-enable",
1711 		.data		= &leases_enable,
1712 		.maxlen		= sizeof(int),
1713 		.mode		= 0644,
1714 		.proc_handler	= proc_dointvec,
1715 	},
1716 #endif
1717 #ifdef CONFIG_DNOTIFY
1718 	{
1719 		.procname	= "dir-notify-enable",
1720 		.data		= &dir_notify_enable,
1721 		.maxlen		= sizeof(int),
1722 		.mode		= 0644,
1723 		.proc_handler	= proc_dointvec,
1724 	},
1725 #endif
1726 #ifdef CONFIG_MMU
1727 #ifdef CONFIG_FILE_LOCKING
1728 	{
1729 		.procname	= "lease-break-time",
1730 		.data		= &lease_break_time,
1731 		.maxlen		= sizeof(int),
1732 		.mode		= 0644,
1733 		.proc_handler	= proc_dointvec,
1734 	},
1735 #endif
1736 #ifdef CONFIG_AIO
1737 	{
1738 		.procname	= "aio-nr",
1739 		.data		= &aio_nr,
1740 		.maxlen		= sizeof(aio_nr),
1741 		.mode		= 0444,
1742 		.proc_handler	= proc_doulongvec_minmax,
1743 	},
1744 	{
1745 		.procname	= "aio-max-nr",
1746 		.data		= &aio_max_nr,
1747 		.maxlen		= sizeof(aio_max_nr),
1748 		.mode		= 0644,
1749 		.proc_handler	= proc_doulongvec_minmax,
1750 	},
1751 #endif /* CONFIG_AIO */
1752 #ifdef CONFIG_INOTIFY_USER
1753 	{
1754 		.procname	= "inotify",
1755 		.mode		= 0555,
1756 		.child		= inotify_table,
1757 	},
1758 #endif
1759 #ifdef CONFIG_EPOLL
1760 	{
1761 		.procname	= "epoll",
1762 		.mode		= 0555,
1763 		.child		= epoll_table,
1764 	},
1765 #endif
1766 #endif
1767 	{
1768 		.procname	= "protected_symlinks",
1769 		.data		= &sysctl_protected_symlinks,
1770 		.maxlen		= sizeof(int),
1771 		.mode		= 0600,
1772 		.proc_handler	= proc_dointvec_minmax,
1773 		.extra1		= &zero,
1774 		.extra2		= &one,
1775 	},
1776 	{
1777 		.procname	= "protected_hardlinks",
1778 		.data		= &sysctl_protected_hardlinks,
1779 		.maxlen		= sizeof(int),
1780 		.mode		= 0600,
1781 		.proc_handler	= proc_dointvec_minmax,
1782 		.extra1		= &zero,
1783 		.extra2		= &one,
1784 	},
1785 	{
1786 		.procname	= "suid_dumpable",
1787 		.data		= &suid_dumpable,
1788 		.maxlen		= sizeof(int),
1789 		.mode		= 0644,
1790 		.proc_handler	= proc_dointvec_minmax_coredump,
1791 		.extra1		= &zero,
1792 		.extra2		= &two,
1793 	},
1794 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1795 	{
1796 		.procname	= "binfmt_misc",
1797 		.mode		= 0555,
1798 		.child		= sysctl_mount_point,
1799 	},
1800 #endif
1801 	{
1802 		.procname	= "pipe-max-size",
1803 		.data		= &pipe_max_size,
1804 		.maxlen		= sizeof(int),
1805 		.mode		= 0644,
1806 		.proc_handler	= &pipe_proc_fn,
1807 		.extra1		= &pipe_min_size,
1808 	},
1809 	{
1810 		.procname	= "pipe-user-pages-hard",
1811 		.data		= &pipe_user_pages_hard,
1812 		.maxlen		= sizeof(pipe_user_pages_hard),
1813 		.mode		= 0644,
1814 		.proc_handler	= proc_doulongvec_minmax,
1815 	},
1816 	{
1817 		.procname	= "pipe-user-pages-soft",
1818 		.data		= &pipe_user_pages_soft,
1819 		.maxlen		= sizeof(pipe_user_pages_soft),
1820 		.mode		= 0644,
1821 		.proc_handler	= proc_doulongvec_minmax,
1822 	},
1823 	{ }
1824 };
1825 
1826 static struct ctl_table debug_table[] = {
1827 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1828 	{
1829 		.procname	= "exception-trace",
1830 		.data		= &show_unhandled_signals,
1831 		.maxlen		= sizeof(int),
1832 		.mode		= 0644,
1833 		.proc_handler	= proc_dointvec
1834 	},
1835 #endif
1836 #if defined(CONFIG_OPTPROBES)
1837 	{
1838 		.procname	= "kprobes-optimization",
1839 		.data		= &sysctl_kprobes_optimization,
1840 		.maxlen		= sizeof(int),
1841 		.mode		= 0644,
1842 		.proc_handler	= proc_kprobes_optimization_handler,
1843 		.extra1		= &zero,
1844 		.extra2		= &one,
1845 	},
1846 #endif
1847 	{ }
1848 };
1849 
1850 static struct ctl_table dev_table[] = {
1851 	{ }
1852 };
1853 
1854 int __init sysctl_init(void)
1855 {
1856 	struct ctl_table_header *hdr;
1857 
1858 	hdr = register_sysctl_table(sysctl_base_table);
1859 	kmemleak_not_leak(hdr);
1860 	return 0;
1861 }
1862 
1863 #endif /* CONFIG_SYSCTL */
1864 
1865 /*
1866  * /proc/sys support
1867  */
1868 
1869 #ifdef CONFIG_PROC_SYSCTL
1870 
1871 static int _proc_do_string(char *data, int maxlen, int write,
1872 			   char __user *buffer,
1873 			   size_t *lenp, loff_t *ppos)
1874 {
1875 	size_t len;
1876 	char __user *p;
1877 	char c;
1878 
1879 	if (!data || !maxlen || !*lenp) {
1880 		*lenp = 0;
1881 		return 0;
1882 	}
1883 
1884 	if (write) {
1885 		if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1886 			/* Only continue writes not past the end of buffer. */
1887 			len = strlen(data);
1888 			if (len > maxlen - 1)
1889 				len = maxlen - 1;
1890 
1891 			if (*ppos > len)
1892 				return 0;
1893 			len = *ppos;
1894 		} else {
1895 			/* Start writing from beginning of buffer. */
1896 			len = 0;
1897 		}
1898 
1899 		*ppos += *lenp;
1900 		p = buffer;
1901 		while ((p - buffer) < *lenp && len < maxlen - 1) {
1902 			if (get_user(c, p++))
1903 				return -EFAULT;
1904 			if (c == 0 || c == '\n')
1905 				break;
1906 			data[len++] = c;
1907 		}
1908 		data[len] = 0;
1909 	} else {
1910 		len = strlen(data);
1911 		if (len > maxlen)
1912 			len = maxlen;
1913 
1914 		if (*ppos > len) {
1915 			*lenp = 0;
1916 			return 0;
1917 		}
1918 
1919 		data += *ppos;
1920 		len  -= *ppos;
1921 
1922 		if (len > *lenp)
1923 			len = *lenp;
1924 		if (len)
1925 			if (copy_to_user(buffer, data, len))
1926 				return -EFAULT;
1927 		if (len < *lenp) {
1928 			if (put_user('\n', buffer + len))
1929 				return -EFAULT;
1930 			len++;
1931 		}
1932 		*lenp = len;
1933 		*ppos += len;
1934 	}
1935 	return 0;
1936 }
1937 
1938 static void warn_sysctl_write(struct ctl_table *table)
1939 {
1940 	pr_warn_once("%s wrote to %s when file position was not 0!\n"
1941 		"This will not be supported in the future. To silence this\n"
1942 		"warning, set kernel.sysctl_writes_strict = -1\n",
1943 		current->comm, table->procname);
1944 }
1945 
1946 /**
1947  * proc_dostring - read a string sysctl
1948  * @table: the sysctl table
1949  * @write: %TRUE if this is a write to the sysctl file
1950  * @buffer: the user buffer
1951  * @lenp: the size of the user buffer
1952  * @ppos: file position
1953  *
1954  * Reads/writes a string from/to the user buffer. If the kernel
1955  * buffer provided is not large enough to hold the string, the
1956  * string is truncated. The copied string is %NULL-terminated.
1957  * If the string is being read by the user process, it is copied
1958  * and a newline '\n' is added. It is truncated if the buffer is
1959  * not large enough.
1960  *
1961  * Returns 0 on success.
1962  */
1963 int proc_dostring(struct ctl_table *table, int write,
1964 		  void __user *buffer, size_t *lenp, loff_t *ppos)
1965 {
1966 	if (write && *ppos && sysctl_writes_strict == SYSCTL_WRITES_WARN)
1967 		warn_sysctl_write(table);
1968 
1969 	return _proc_do_string((char *)(table->data), table->maxlen, write,
1970 			       (char __user *)buffer, lenp, ppos);
1971 }
1972 
1973 static size_t proc_skip_spaces(char **buf)
1974 {
1975 	size_t ret;
1976 	char *tmp = skip_spaces(*buf);
1977 	ret = tmp - *buf;
1978 	*buf = tmp;
1979 	return ret;
1980 }
1981 
1982 static void proc_skip_char(char **buf, size_t *size, const char v)
1983 {
1984 	while (*size) {
1985 		if (**buf != v)
1986 			break;
1987 		(*size)--;
1988 		(*buf)++;
1989 	}
1990 }
1991 
1992 #define TMPBUFLEN 22
1993 /**
1994  * proc_get_long - reads an ASCII formatted integer from a user buffer
1995  *
1996  * @buf: a kernel buffer
1997  * @size: size of the kernel buffer
1998  * @val: this is where the number will be stored
1999  * @neg: set to %TRUE if number is negative
2000  * @perm_tr: a vector which contains the allowed trailers
2001  * @perm_tr_len: size of the perm_tr vector
2002  * @tr: pointer to store the trailer character
2003  *
2004  * In case of success %0 is returned and @buf and @size are updated with
2005  * the amount of bytes read. If @tr is non-NULL and a trailing
2006  * character exists (size is non-zero after returning from this
2007  * function), @tr is updated with the trailing character.
2008  */
2009 static int proc_get_long(char **buf, size_t *size,
2010 			  unsigned long *val, bool *neg,
2011 			  const char *perm_tr, unsigned perm_tr_len, char *tr)
2012 {
2013 	int len;
2014 	char *p, tmp[TMPBUFLEN];
2015 
2016 	if (!*size)
2017 		return -EINVAL;
2018 
2019 	len = *size;
2020 	if (len > TMPBUFLEN - 1)
2021 		len = TMPBUFLEN - 1;
2022 
2023 	memcpy(tmp, *buf, len);
2024 
2025 	tmp[len] = 0;
2026 	p = tmp;
2027 	if (*p == '-' && *size > 1) {
2028 		*neg = true;
2029 		p++;
2030 	} else
2031 		*neg = false;
2032 	if (!isdigit(*p))
2033 		return -EINVAL;
2034 
2035 	*val = simple_strtoul(p, &p, 0);
2036 
2037 	len = p - tmp;
2038 
2039 	/* We don't know if the next char is whitespace thus we may accept
2040 	 * invalid integers (e.g. 1234...a) or two integers instead of one
2041 	 * (e.g. 123...1). So lets not allow such large numbers. */
2042 	if (len == TMPBUFLEN - 1)
2043 		return -EINVAL;
2044 
2045 	if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2046 		return -EINVAL;
2047 
2048 	if (tr && (len < *size))
2049 		*tr = *p;
2050 
2051 	*buf += len;
2052 	*size -= len;
2053 
2054 	return 0;
2055 }
2056 
2057 /**
2058  * proc_put_long - converts an integer to a decimal ASCII formatted string
2059  *
2060  * @buf: the user buffer
2061  * @size: the size of the user buffer
2062  * @val: the integer to be converted
2063  * @neg: sign of the number, %TRUE for negative
2064  *
2065  * In case of success %0 is returned and @buf and @size are updated with
2066  * the amount of bytes written.
2067  */
2068 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2069 			  bool neg)
2070 {
2071 	int len;
2072 	char tmp[TMPBUFLEN], *p = tmp;
2073 
2074 	sprintf(p, "%s%lu", neg ? "-" : "", val);
2075 	len = strlen(tmp);
2076 	if (len > *size)
2077 		len = *size;
2078 	if (copy_to_user(*buf, tmp, len))
2079 		return -EFAULT;
2080 	*size -= len;
2081 	*buf += len;
2082 	return 0;
2083 }
2084 #undef TMPBUFLEN
2085 
2086 static int proc_put_char(void __user **buf, size_t *size, char c)
2087 {
2088 	if (*size) {
2089 		char __user **buffer = (char __user **)buf;
2090 		if (put_user(c, *buffer))
2091 			return -EFAULT;
2092 		(*size)--, (*buffer)++;
2093 		*buf = *buffer;
2094 	}
2095 	return 0;
2096 }
2097 
2098 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2099 				 int *valp,
2100 				 int write, void *data)
2101 {
2102 	if (write) {
2103 		if (*negp) {
2104 			if (*lvalp > (unsigned long) INT_MAX + 1)
2105 				return -EINVAL;
2106 			*valp = -*lvalp;
2107 		} else {
2108 			if (*lvalp > (unsigned long) INT_MAX)
2109 				return -EINVAL;
2110 			*valp = *lvalp;
2111 		}
2112 	} else {
2113 		int val = *valp;
2114 		if (val < 0) {
2115 			*negp = true;
2116 			*lvalp = -(unsigned long)val;
2117 		} else {
2118 			*negp = false;
2119 			*lvalp = (unsigned long)val;
2120 		}
2121 	}
2122 	return 0;
2123 }
2124 
2125 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2126 
2127 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2128 		  int write, void __user *buffer,
2129 		  size_t *lenp, loff_t *ppos,
2130 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2131 			      int write, void *data),
2132 		  void *data)
2133 {
2134 	int *i, vleft, first = 1, err = 0;
2135 	size_t left;
2136 	char *kbuf = NULL, *p;
2137 
2138 	if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2139 		*lenp = 0;
2140 		return 0;
2141 	}
2142 
2143 	i = (int *) tbl_data;
2144 	vleft = table->maxlen / sizeof(*i);
2145 	left = *lenp;
2146 
2147 	if (!conv)
2148 		conv = do_proc_dointvec_conv;
2149 
2150 	if (write) {
2151 		if (*ppos) {
2152 			switch (sysctl_writes_strict) {
2153 			case SYSCTL_WRITES_STRICT:
2154 				goto out;
2155 			case SYSCTL_WRITES_WARN:
2156 				warn_sysctl_write(table);
2157 				break;
2158 			default:
2159 				break;
2160 			}
2161 		}
2162 
2163 		if (left > PAGE_SIZE - 1)
2164 			left = PAGE_SIZE - 1;
2165 		p = kbuf = memdup_user_nul(buffer, left);
2166 		if (IS_ERR(kbuf))
2167 			return PTR_ERR(kbuf);
2168 	}
2169 
2170 	for (; left && vleft--; i++, first=0) {
2171 		unsigned long lval;
2172 		bool neg;
2173 
2174 		if (write) {
2175 			left -= proc_skip_spaces(&p);
2176 
2177 			if (!left)
2178 				break;
2179 			err = proc_get_long(&p, &left, &lval, &neg,
2180 					     proc_wspace_sep,
2181 					     sizeof(proc_wspace_sep), NULL);
2182 			if (err)
2183 				break;
2184 			if (conv(&neg, &lval, i, 1, data)) {
2185 				err = -EINVAL;
2186 				break;
2187 			}
2188 		} else {
2189 			if (conv(&neg, &lval, i, 0, data)) {
2190 				err = -EINVAL;
2191 				break;
2192 			}
2193 			if (!first)
2194 				err = proc_put_char(&buffer, &left, '\t');
2195 			if (err)
2196 				break;
2197 			err = proc_put_long(&buffer, &left, lval, neg);
2198 			if (err)
2199 				break;
2200 		}
2201 	}
2202 
2203 	if (!write && !first && left && !err)
2204 		err = proc_put_char(&buffer, &left, '\n');
2205 	if (write && !err && left)
2206 		left -= proc_skip_spaces(&p);
2207 	if (write) {
2208 		kfree(kbuf);
2209 		if (first)
2210 			return err ? : -EINVAL;
2211 	}
2212 	*lenp -= left;
2213 out:
2214 	*ppos += *lenp;
2215 	return err;
2216 }
2217 
2218 static int do_proc_dointvec(struct ctl_table *table, int write,
2219 		  void __user *buffer, size_t *lenp, loff_t *ppos,
2220 		  int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2221 			      int write, void *data),
2222 		  void *data)
2223 {
2224 	return __do_proc_dointvec(table->data, table, write,
2225 			buffer, lenp, ppos, conv, data);
2226 }
2227 
2228 /**
2229  * proc_dointvec - read a vector of integers
2230  * @table: the sysctl table
2231  * @write: %TRUE if this is a write to the sysctl file
2232  * @buffer: the user buffer
2233  * @lenp: the size of the user buffer
2234  * @ppos: file position
2235  *
2236  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2237  * values from/to the user buffer, treated as an ASCII string.
2238  *
2239  * Returns 0 on success.
2240  */
2241 int proc_dointvec(struct ctl_table *table, int write,
2242 		     void __user *buffer, size_t *lenp, loff_t *ppos)
2243 {
2244     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2245 		    	    NULL,NULL);
2246 }
2247 
2248 /*
2249  * Taint values can only be increased
2250  * This means we can safely use a temporary.
2251  */
2252 static int proc_taint(struct ctl_table *table, int write,
2253 			       void __user *buffer, size_t *lenp, loff_t *ppos)
2254 {
2255 	struct ctl_table t;
2256 	unsigned long tmptaint = get_taint();
2257 	int err;
2258 
2259 	if (write && !capable(CAP_SYS_ADMIN))
2260 		return -EPERM;
2261 
2262 	t = *table;
2263 	t.data = &tmptaint;
2264 	err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2265 	if (err < 0)
2266 		return err;
2267 
2268 	if (write) {
2269 		/*
2270 		 * Poor man's atomic or. Not worth adding a primitive
2271 		 * to everyone's atomic.h for this
2272 		 */
2273 		int i;
2274 		for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2275 			if ((tmptaint >> i) & 1)
2276 				add_taint(i, LOCKDEP_STILL_OK);
2277 		}
2278 	}
2279 
2280 	return err;
2281 }
2282 
2283 #ifdef CONFIG_PRINTK
2284 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2285 				void __user *buffer, size_t *lenp, loff_t *ppos)
2286 {
2287 	if (write && !capable(CAP_SYS_ADMIN))
2288 		return -EPERM;
2289 
2290 	return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2291 }
2292 #endif
2293 
2294 struct do_proc_dointvec_minmax_conv_param {
2295 	int *min;
2296 	int *max;
2297 };
2298 
2299 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2300 					int *valp,
2301 					int write, void *data)
2302 {
2303 	struct do_proc_dointvec_minmax_conv_param *param = data;
2304 	if (write) {
2305 		int val = *negp ? -*lvalp : *lvalp;
2306 		if ((param->min && *param->min > val) ||
2307 		    (param->max && *param->max < val))
2308 			return -EINVAL;
2309 		*valp = val;
2310 	} else {
2311 		int val = *valp;
2312 		if (val < 0) {
2313 			*negp = true;
2314 			*lvalp = -(unsigned long)val;
2315 		} else {
2316 			*negp = false;
2317 			*lvalp = (unsigned long)val;
2318 		}
2319 	}
2320 	return 0;
2321 }
2322 
2323 /**
2324  * proc_dointvec_minmax - read a vector of integers with min/max values
2325  * @table: the sysctl table
2326  * @write: %TRUE if this is a write to the sysctl file
2327  * @buffer: the user buffer
2328  * @lenp: the size of the user buffer
2329  * @ppos: file position
2330  *
2331  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2332  * values from/to the user buffer, treated as an ASCII string.
2333  *
2334  * This routine will ensure the values are within the range specified by
2335  * table->extra1 (min) and table->extra2 (max).
2336  *
2337  * Returns 0 on success.
2338  */
2339 int proc_dointvec_minmax(struct ctl_table *table, int write,
2340 		  void __user *buffer, size_t *lenp, loff_t *ppos)
2341 {
2342 	struct do_proc_dointvec_minmax_conv_param param = {
2343 		.min = (int *) table->extra1,
2344 		.max = (int *) table->extra2,
2345 	};
2346 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
2347 				do_proc_dointvec_minmax_conv, &param);
2348 }
2349 
2350 static void validate_coredump_safety(void)
2351 {
2352 #ifdef CONFIG_COREDUMP
2353 	if (suid_dumpable == SUID_DUMP_ROOT &&
2354 	    core_pattern[0] != '/' && core_pattern[0] != '|') {
2355 		printk(KERN_WARNING "Unsafe core_pattern used with "\
2356 			"suid_dumpable=2. Pipe handler or fully qualified "\
2357 			"core dump path required.\n");
2358 	}
2359 #endif
2360 }
2361 
2362 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2363 		void __user *buffer, size_t *lenp, loff_t *ppos)
2364 {
2365 	int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2366 	if (!error)
2367 		validate_coredump_safety();
2368 	return error;
2369 }
2370 
2371 #ifdef CONFIG_COREDUMP
2372 static int proc_dostring_coredump(struct ctl_table *table, int write,
2373 		  void __user *buffer, size_t *lenp, loff_t *ppos)
2374 {
2375 	int error = proc_dostring(table, write, buffer, lenp, ppos);
2376 	if (!error)
2377 		validate_coredump_safety();
2378 	return error;
2379 }
2380 #endif
2381 
2382 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2383 				     void __user *buffer,
2384 				     size_t *lenp, loff_t *ppos,
2385 				     unsigned long convmul,
2386 				     unsigned long convdiv)
2387 {
2388 	unsigned long *i, *min, *max;
2389 	int vleft, first = 1, err = 0;
2390 	size_t left;
2391 	char *kbuf = NULL, *p;
2392 
2393 	if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2394 		*lenp = 0;
2395 		return 0;
2396 	}
2397 
2398 	i = (unsigned long *) data;
2399 	min = (unsigned long *) table->extra1;
2400 	max = (unsigned long *) table->extra2;
2401 	vleft = table->maxlen / sizeof(unsigned long);
2402 	left = *lenp;
2403 
2404 	if (write) {
2405 		if (*ppos) {
2406 			switch (sysctl_writes_strict) {
2407 			case SYSCTL_WRITES_STRICT:
2408 				goto out;
2409 			case SYSCTL_WRITES_WARN:
2410 				warn_sysctl_write(table);
2411 				break;
2412 			default:
2413 				break;
2414 			}
2415 		}
2416 
2417 		if (left > PAGE_SIZE - 1)
2418 			left = PAGE_SIZE - 1;
2419 		p = kbuf = memdup_user_nul(buffer, left);
2420 		if (IS_ERR(kbuf))
2421 			return PTR_ERR(kbuf);
2422 	}
2423 
2424 	for (; left && vleft--; i++, first = 0) {
2425 		unsigned long val;
2426 
2427 		if (write) {
2428 			bool neg;
2429 
2430 			left -= proc_skip_spaces(&p);
2431 
2432 			err = proc_get_long(&p, &left, &val, &neg,
2433 					     proc_wspace_sep,
2434 					     sizeof(proc_wspace_sep), NULL);
2435 			if (err)
2436 				break;
2437 			if (neg)
2438 				continue;
2439 			if ((min && val < *min) || (max && val > *max))
2440 				continue;
2441 			*i = val;
2442 		} else {
2443 			val = convdiv * (*i) / convmul;
2444 			if (!first) {
2445 				err = proc_put_char(&buffer, &left, '\t');
2446 				if (err)
2447 					break;
2448 			}
2449 			err = proc_put_long(&buffer, &left, val, false);
2450 			if (err)
2451 				break;
2452 		}
2453 	}
2454 
2455 	if (!write && !first && left && !err)
2456 		err = proc_put_char(&buffer, &left, '\n');
2457 	if (write && !err)
2458 		left -= proc_skip_spaces(&p);
2459 	if (write) {
2460 		kfree(kbuf);
2461 		if (first)
2462 			return err ? : -EINVAL;
2463 	}
2464 	*lenp -= left;
2465 out:
2466 	*ppos += *lenp;
2467 	return err;
2468 }
2469 
2470 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2471 				     void __user *buffer,
2472 				     size_t *lenp, loff_t *ppos,
2473 				     unsigned long convmul,
2474 				     unsigned long convdiv)
2475 {
2476 	return __do_proc_doulongvec_minmax(table->data, table, write,
2477 			buffer, lenp, ppos, convmul, convdiv);
2478 }
2479 
2480 /**
2481  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2482  * @table: the sysctl table
2483  * @write: %TRUE if this is a write to the sysctl file
2484  * @buffer: the user buffer
2485  * @lenp: the size of the user buffer
2486  * @ppos: file position
2487  *
2488  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2489  * values from/to the user buffer, treated as an ASCII string.
2490  *
2491  * This routine will ensure the values are within the range specified by
2492  * table->extra1 (min) and table->extra2 (max).
2493  *
2494  * Returns 0 on success.
2495  */
2496 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2497 			   void __user *buffer, size_t *lenp, loff_t *ppos)
2498 {
2499     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2500 }
2501 
2502 /**
2503  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2504  * @table: the sysctl table
2505  * @write: %TRUE if this is a write to the sysctl file
2506  * @buffer: the user buffer
2507  * @lenp: the size of the user buffer
2508  * @ppos: file position
2509  *
2510  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2511  * values from/to the user buffer, treated as an ASCII string. The values
2512  * are treated as milliseconds, and converted to jiffies when they are stored.
2513  *
2514  * This routine will ensure the values are within the range specified by
2515  * table->extra1 (min) and table->extra2 (max).
2516  *
2517  * Returns 0 on success.
2518  */
2519 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2520 				      void __user *buffer,
2521 				      size_t *lenp, loff_t *ppos)
2522 {
2523     return do_proc_doulongvec_minmax(table, write, buffer,
2524 				     lenp, ppos, HZ, 1000l);
2525 }
2526 
2527 
2528 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
2529 					 int *valp,
2530 					 int write, void *data)
2531 {
2532 	if (write) {
2533 		if (*lvalp > LONG_MAX / HZ)
2534 			return 1;
2535 		*valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
2536 	} else {
2537 		int val = *valp;
2538 		unsigned long lval;
2539 		if (val < 0) {
2540 			*negp = true;
2541 			lval = -(unsigned long)val;
2542 		} else {
2543 			*negp = false;
2544 			lval = (unsigned long)val;
2545 		}
2546 		*lvalp = lval / HZ;
2547 	}
2548 	return 0;
2549 }
2550 
2551 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
2552 						int *valp,
2553 						int write, void *data)
2554 {
2555 	if (write) {
2556 		if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
2557 			return 1;
2558 		*valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
2559 	} else {
2560 		int val = *valp;
2561 		unsigned long lval;
2562 		if (val < 0) {
2563 			*negp = true;
2564 			lval = -(unsigned long)val;
2565 		} else {
2566 			*negp = false;
2567 			lval = (unsigned long)val;
2568 		}
2569 		*lvalp = jiffies_to_clock_t(lval);
2570 	}
2571 	return 0;
2572 }
2573 
2574 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
2575 					    int *valp,
2576 					    int write, void *data)
2577 {
2578 	if (write) {
2579 		unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
2580 
2581 		if (jif > INT_MAX)
2582 			return 1;
2583 		*valp = (int)jif;
2584 	} else {
2585 		int val = *valp;
2586 		unsigned long lval;
2587 		if (val < 0) {
2588 			*negp = true;
2589 			lval = -(unsigned long)val;
2590 		} else {
2591 			*negp = false;
2592 			lval = (unsigned long)val;
2593 		}
2594 		*lvalp = jiffies_to_msecs(lval);
2595 	}
2596 	return 0;
2597 }
2598 
2599 /**
2600  * proc_dointvec_jiffies - read a vector of integers as seconds
2601  * @table: the sysctl table
2602  * @write: %TRUE if this is a write to the sysctl file
2603  * @buffer: the user buffer
2604  * @lenp: the size of the user buffer
2605  * @ppos: file position
2606  *
2607  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2608  * values from/to the user buffer, treated as an ASCII string.
2609  * The values read are assumed to be in seconds, and are converted into
2610  * jiffies.
2611  *
2612  * Returns 0 on success.
2613  */
2614 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2615 			  void __user *buffer, size_t *lenp, loff_t *ppos)
2616 {
2617     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2618 		    	    do_proc_dointvec_jiffies_conv,NULL);
2619 }
2620 
2621 /**
2622  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
2623  * @table: the sysctl table
2624  * @write: %TRUE if this is a write to the sysctl file
2625  * @buffer: the user buffer
2626  * @lenp: the size of the user buffer
2627  * @ppos: pointer to the file position
2628  *
2629  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2630  * values from/to the user buffer, treated as an ASCII string.
2631  * The values read are assumed to be in 1/USER_HZ seconds, and
2632  * are converted into jiffies.
2633  *
2634  * Returns 0 on success.
2635  */
2636 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2637 				 void __user *buffer, size_t *lenp, loff_t *ppos)
2638 {
2639     return do_proc_dointvec(table,write,buffer,lenp,ppos,
2640 		    	    do_proc_dointvec_userhz_jiffies_conv,NULL);
2641 }
2642 
2643 /**
2644  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
2645  * @table: the sysctl table
2646  * @write: %TRUE if this is a write to the sysctl file
2647  * @buffer: the user buffer
2648  * @lenp: the size of the user buffer
2649  * @ppos: file position
2650  * @ppos: the current position in the file
2651  *
2652  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2653  * values from/to the user buffer, treated as an ASCII string.
2654  * The values read are assumed to be in 1/1000 seconds, and
2655  * are converted into jiffies.
2656  *
2657  * Returns 0 on success.
2658  */
2659 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2660 			     void __user *buffer, size_t *lenp, loff_t *ppos)
2661 {
2662 	return do_proc_dointvec(table, write, buffer, lenp, ppos,
2663 				do_proc_dointvec_ms_jiffies_conv, NULL);
2664 }
2665 
2666 static int proc_do_cad_pid(struct ctl_table *table, int write,
2667 			   void __user *buffer, size_t *lenp, loff_t *ppos)
2668 {
2669 	struct pid *new_pid;
2670 	pid_t tmp;
2671 	int r;
2672 
2673 	tmp = pid_vnr(cad_pid);
2674 
2675 	r = __do_proc_dointvec(&tmp, table, write, buffer,
2676 			       lenp, ppos, NULL, NULL);
2677 	if (r || !write)
2678 		return r;
2679 
2680 	new_pid = find_get_pid(tmp);
2681 	if (!new_pid)
2682 		return -ESRCH;
2683 
2684 	put_pid(xchg(&cad_pid, new_pid));
2685 	return 0;
2686 }
2687 
2688 /**
2689  * proc_do_large_bitmap - read/write from/to a large bitmap
2690  * @table: the sysctl table
2691  * @write: %TRUE if this is a write to the sysctl file
2692  * @buffer: the user buffer
2693  * @lenp: the size of the user buffer
2694  * @ppos: file position
2695  *
2696  * The bitmap is stored at table->data and the bitmap length (in bits)
2697  * in table->maxlen.
2698  *
2699  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
2700  * large bitmaps may be represented in a compact manner. Writing into
2701  * the file will clear the bitmap then update it with the given input.
2702  *
2703  * Returns 0 on success.
2704  */
2705 int proc_do_large_bitmap(struct ctl_table *table, int write,
2706 			 void __user *buffer, size_t *lenp, loff_t *ppos)
2707 {
2708 	int err = 0;
2709 	bool first = 1;
2710 	size_t left = *lenp;
2711 	unsigned long bitmap_len = table->maxlen;
2712 	unsigned long *bitmap = *(unsigned long **) table->data;
2713 	unsigned long *tmp_bitmap = NULL;
2714 	char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
2715 
2716 	if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
2717 		*lenp = 0;
2718 		return 0;
2719 	}
2720 
2721 	if (write) {
2722 		char *kbuf, *p;
2723 
2724 		if (left > PAGE_SIZE - 1)
2725 			left = PAGE_SIZE - 1;
2726 
2727 		p = kbuf = memdup_user_nul(buffer, left);
2728 		if (IS_ERR(kbuf))
2729 			return PTR_ERR(kbuf);
2730 
2731 		tmp_bitmap = kzalloc(BITS_TO_LONGS(bitmap_len) * sizeof(unsigned long),
2732 				     GFP_KERNEL);
2733 		if (!tmp_bitmap) {
2734 			kfree(kbuf);
2735 			return -ENOMEM;
2736 		}
2737 		proc_skip_char(&p, &left, '\n');
2738 		while (!err && left) {
2739 			unsigned long val_a, val_b;
2740 			bool neg;
2741 
2742 			err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
2743 					     sizeof(tr_a), &c);
2744 			if (err)
2745 				break;
2746 			if (val_a >= bitmap_len || neg) {
2747 				err = -EINVAL;
2748 				break;
2749 			}
2750 
2751 			val_b = val_a;
2752 			if (left) {
2753 				p++;
2754 				left--;
2755 			}
2756 
2757 			if (c == '-') {
2758 				err = proc_get_long(&p, &left, &val_b,
2759 						     &neg, tr_b, sizeof(tr_b),
2760 						     &c);
2761 				if (err)
2762 					break;
2763 				if (val_b >= bitmap_len || neg ||
2764 				    val_a > val_b) {
2765 					err = -EINVAL;
2766 					break;
2767 				}
2768 				if (left) {
2769 					p++;
2770 					left--;
2771 				}
2772 			}
2773 
2774 			bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
2775 			first = 0;
2776 			proc_skip_char(&p, &left, '\n');
2777 		}
2778 		kfree(kbuf);
2779 	} else {
2780 		unsigned long bit_a, bit_b = 0;
2781 
2782 		while (left) {
2783 			bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
2784 			if (bit_a >= bitmap_len)
2785 				break;
2786 			bit_b = find_next_zero_bit(bitmap, bitmap_len,
2787 						   bit_a + 1) - 1;
2788 
2789 			if (!first) {
2790 				err = proc_put_char(&buffer, &left, ',');
2791 				if (err)
2792 					break;
2793 			}
2794 			err = proc_put_long(&buffer, &left, bit_a, false);
2795 			if (err)
2796 				break;
2797 			if (bit_a != bit_b) {
2798 				err = proc_put_char(&buffer, &left, '-');
2799 				if (err)
2800 					break;
2801 				err = proc_put_long(&buffer, &left, bit_b, false);
2802 				if (err)
2803 					break;
2804 			}
2805 
2806 			first = 0; bit_b++;
2807 		}
2808 		if (!err)
2809 			err = proc_put_char(&buffer, &left, '\n');
2810 	}
2811 
2812 	if (!err) {
2813 		if (write) {
2814 			if (*ppos)
2815 				bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
2816 			else
2817 				bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
2818 		}
2819 		kfree(tmp_bitmap);
2820 		*lenp -= left;
2821 		*ppos += *lenp;
2822 		return 0;
2823 	} else {
2824 		kfree(tmp_bitmap);
2825 		return err;
2826 	}
2827 }
2828 
2829 #else /* CONFIG_PROC_SYSCTL */
2830 
2831 int proc_dostring(struct ctl_table *table, int write,
2832 		  void __user *buffer, size_t *lenp, loff_t *ppos)
2833 {
2834 	return -ENOSYS;
2835 }
2836 
2837 int proc_dointvec(struct ctl_table *table, int write,
2838 		  void __user *buffer, size_t *lenp, loff_t *ppos)
2839 {
2840 	return -ENOSYS;
2841 }
2842 
2843 int proc_dointvec_minmax(struct ctl_table *table, int write,
2844 		    void __user *buffer, size_t *lenp, loff_t *ppos)
2845 {
2846 	return -ENOSYS;
2847 }
2848 
2849 int proc_dointvec_jiffies(struct ctl_table *table, int write,
2850 		    void __user *buffer, size_t *lenp, loff_t *ppos)
2851 {
2852 	return -ENOSYS;
2853 }
2854 
2855 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
2856 		    void __user *buffer, size_t *lenp, loff_t *ppos)
2857 {
2858 	return -ENOSYS;
2859 }
2860 
2861 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
2862 			     void __user *buffer, size_t *lenp, loff_t *ppos)
2863 {
2864 	return -ENOSYS;
2865 }
2866 
2867 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2868 		    void __user *buffer, size_t *lenp, loff_t *ppos)
2869 {
2870 	return -ENOSYS;
2871 }
2872 
2873 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
2874 				      void __user *buffer,
2875 				      size_t *lenp, loff_t *ppos)
2876 {
2877     return -ENOSYS;
2878 }
2879 
2880 
2881 #endif /* CONFIG_PROC_SYSCTL */
2882 
2883 /*
2884  * No sense putting this after each symbol definition, twice,
2885  * exception granted :-)
2886  */
2887 EXPORT_SYMBOL(proc_dointvec);
2888 EXPORT_SYMBOL(proc_dointvec_jiffies);
2889 EXPORT_SYMBOL(proc_dointvec_minmax);
2890 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
2891 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
2892 EXPORT_SYMBOL(proc_dostring);
2893 EXPORT_SYMBOL(proc_doulongvec_minmax);
2894 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
2895