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