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