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