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