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