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