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