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