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