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