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