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