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