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