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