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