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