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