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