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