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