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