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