OSDN Git Service

Merge tag 'efi-core-2020-06-01' of git://git.kernel.org/pub/scm/linux/kernel/git...
[tomoyo/tomoyo-test1.git] / kernel / sysctl.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * sysctl.c: General linux system control interface
4  *
5  * Begun 24 March 1995, Stephen Tweedie
6  * Added /proc support, Dec 1995
7  * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas.
8  * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver.
9  * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver.
10  * Dynamic registration fixes, Stephen Tweedie.
11  * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn.
12  * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris
13  *  Horn.
14  * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer.
15  * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer.
16  * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill
17  *  Wendling.
18  * The list_for_each() macro wasn't appropriate for the sysctl loop.
19  *  Removed it and replaced it with older style, 03/23/00, Bill Wendling
20  */
21
22 #include <linux/module.h>
23 #include <linux/aio.h>
24 #include <linux/mm.h>
25 #include <linux/swap.h>
26 #include <linux/slab.h>
27 #include <linux/sysctl.h>
28 #include <linux/bitmap.h>
29 #include <linux/signal.h>
30 #include <linux/printk.h>
31 #include <linux/proc_fs.h>
32 #include <linux/security.h>
33 #include <linux/ctype.h>
34 #include <linux/kmemleak.h>
35 #include <linux/fs.h>
36 #include <linux/init.h>
37 #include <linux/kernel.h>
38 #include <linux/kobject.h>
39 #include <linux/net.h>
40 #include <linux/sysrq.h>
41 #include <linux/highuid.h>
42 #include <linux/writeback.h>
43 #include <linux/ratelimit.h>
44 #include <linux/compaction.h>
45 #include <linux/hugetlb.h>
46 #include <linux/initrd.h>
47 #include <linux/key.h>
48 #include <linux/times.h>
49 #include <linux/limits.h>
50 #include <linux/dcache.h>
51 #include <linux/dnotify.h>
52 #include <linux/syscalls.h>
53 #include <linux/vmstat.h>
54 #include <linux/nfs_fs.h>
55 #include <linux/acpi.h>
56 #include <linux/reboot.h>
57 #include <linux/ftrace.h>
58 #include <linux/perf_event.h>
59 #include <linux/kprobes.h>
60 #include <linux/pipe_fs_i.h>
61 #include <linux/oom.h>
62 #include <linux/kmod.h>
63 #include <linux/capability.h>
64 #include <linux/binfmts.h>
65 #include <linux/sched/sysctl.h>
66 #include <linux/sched/coredump.h>
67 #include <linux/kexec.h>
68 #include <linux/bpf.h>
69 #include <linux/mount.h>
70 #include <linux/userfaultfd_k.h>
71
72 #include "../lib/kstrtox.h"
73
74 #include <linux/uaccess.h>
75 #include <asm/processor.h>
76
77 #ifdef CONFIG_X86
78 #include <asm/nmi.h>
79 #include <asm/stacktrace.h>
80 #include <asm/io.h>
81 #endif
82 #ifdef CONFIG_SPARC
83 #include <asm/setup.h>
84 #endif
85 #ifdef CONFIG_BSD_PROCESS_ACCT
86 #include <linux/acct.h>
87 #endif
88 #ifdef CONFIG_RT_MUTEXES
89 #include <linux/rtmutex.h>
90 #endif
91 #if defined(CONFIG_PROVE_LOCKING) || defined(CONFIG_LOCK_STAT)
92 #include <linux/lockdep.h>
93 #endif
94 #ifdef CONFIG_CHR_DEV_SG
95 #include <scsi/sg.h>
96 #endif
97 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
98 #include <linux/stackleak.h>
99 #endif
100 #ifdef CONFIG_LOCKUP_DETECTOR
101 #include <linux/nmi.h>
102 #endif
103
104 #if defined(CONFIG_SYSCTL)
105
106 /* External variables not in a header file. */
107 extern int suid_dumpable;
108 #ifdef CONFIG_COREDUMP
109 extern int core_uses_pid;
110 extern char core_pattern[];
111 extern unsigned int core_pipe_limit;
112 #endif
113 extern int pid_max;
114 extern int pid_max_min, pid_max_max;
115 extern int percpu_pagelist_fraction;
116 extern int latencytop_enabled;
117 extern unsigned int sysctl_nr_open_min, sysctl_nr_open_max;
118 #ifndef CONFIG_MMU
119 extern int sysctl_nr_trim_pages;
120 #endif
121
122 /* Constants used for minimum and  maximum */
123 #ifdef CONFIG_LOCKUP_DETECTOR
124 static int sixty = 60;
125 #endif
126
127 static int __maybe_unused neg_one = -1;
128 static int __maybe_unused two = 2;
129 static int __maybe_unused four = 4;
130 static unsigned long zero_ul;
131 static unsigned long one_ul = 1;
132 static unsigned long long_max = LONG_MAX;
133 static int one_hundred = 100;
134 static int one_thousand = 1000;
135 #ifdef CONFIG_PRINTK
136 static int ten_thousand = 10000;
137 #endif
138 #ifdef CONFIG_PERF_EVENTS
139 static int six_hundred_forty_kb = 640 * 1024;
140 #endif
141
142 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
143 static unsigned long dirty_bytes_min = 2 * PAGE_SIZE;
144
145 /* this is needed for the proc_dointvec_minmax for [fs_]overflow UID and GID */
146 static int maxolduid = 65535;
147 static int minolduid;
148
149 static int ngroups_max = NGROUPS_MAX;
150 static const int cap_last_cap = CAP_LAST_CAP;
151
152 /*
153  * This is needed for proc_doulongvec_minmax of sysctl_hung_task_timeout_secs
154  * and hung_task_check_interval_secs
155  */
156 #ifdef CONFIG_DETECT_HUNG_TASK
157 static unsigned long hung_task_timeout_max = (LONG_MAX/HZ);
158 #endif
159
160 #ifdef CONFIG_INOTIFY_USER
161 #include <linux/inotify.h>
162 #endif
163 #ifdef CONFIG_SPARC
164 #endif
165
166 #ifdef CONFIG_PARISC
167 extern int pwrsw_enabled;
168 #endif
169
170 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
171 extern int unaligned_enabled;
172 #endif
173
174 #ifdef CONFIG_IA64
175 extern int unaligned_dump_stack;
176 #endif
177
178 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
179 extern int no_unaligned_warning;
180 #endif
181
182 #ifdef CONFIG_PROC_SYSCTL
183
184 /**
185  * enum sysctl_writes_mode - supported sysctl write modes
186  *
187  * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value
188  *      to be written, and multiple writes on the same sysctl file descriptor
189  *      will rewrite the sysctl value, regardless of file position. No warning
190  *      is issued when the initial position is not 0.
191  * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is
192  *      not 0.
193  * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at
194  *      file position 0 and the value must be fully contained in the buffer
195  *      sent to the write syscall. If dealing with strings respect the file
196  *      position, but restrict this to the max length of the buffer, anything
197  *      passed the max length will be ignored. Multiple writes will append
198  *      to the buffer.
199  *
200  * These write modes control how current file position affects the behavior of
201  * updating sysctl values through the proc interface on each write.
202  */
203 enum sysctl_writes_mode {
204         SYSCTL_WRITES_LEGACY            = -1,
205         SYSCTL_WRITES_WARN              = 0,
206         SYSCTL_WRITES_STRICT            = 1,
207 };
208
209 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT;
210
211 static int proc_do_cad_pid(struct ctl_table *table, int write,
212                   void __user *buffer, size_t *lenp, loff_t *ppos);
213 static int proc_taint(struct ctl_table *table, int write,
214                                void __user *buffer, size_t *lenp, loff_t *ppos);
215 #ifdef CONFIG_COMPACTION
216 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
217                                                int write, void __user *buffer,
218                                                size_t *lenp, loff_t *ppos);
219 #endif
220 #endif
221
222 #ifdef CONFIG_PRINTK
223 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
224                                 void __user *buffer, size_t *lenp, loff_t *ppos);
225 #endif
226
227 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
228                 void __user *buffer, size_t *lenp, loff_t *ppos);
229 #ifdef CONFIG_COREDUMP
230 static int proc_dostring_coredump(struct ctl_table *table, int write,
231                 void __user *buffer, size_t *lenp, loff_t *ppos);
232 #endif
233 static int proc_dopipe_max_size(struct ctl_table *table, int write,
234                 void __user *buffer, size_t *lenp, loff_t *ppos);
235
236 #ifdef CONFIG_MAGIC_SYSRQ
237 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
238                         void __user *buffer, size_t *lenp, loff_t *ppos);
239 #endif
240
241 static struct ctl_table kern_table[];
242 static struct ctl_table vm_table[];
243 static struct ctl_table fs_table[];
244 static struct ctl_table debug_table[];
245 static struct ctl_table dev_table[];
246 extern struct ctl_table random_table[];
247 #ifdef CONFIG_EPOLL
248 extern struct ctl_table epoll_table[];
249 #endif
250
251 #ifdef CONFIG_FW_LOADER_USER_HELPER
252 extern struct ctl_table firmware_config_table[];
253 #endif
254
255 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
256     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
257 int sysctl_legacy_va_layout;
258 #endif
259
260 /* The default sysctl tables: */
261
262 static struct ctl_table sysctl_base_table[] = {
263         {
264                 .procname       = "kernel",
265                 .mode           = 0555,
266                 .child          = kern_table,
267         },
268         {
269                 .procname       = "vm",
270                 .mode           = 0555,
271                 .child          = vm_table,
272         },
273         {
274                 .procname       = "fs",
275                 .mode           = 0555,
276                 .child          = fs_table,
277         },
278         {
279                 .procname       = "debug",
280                 .mode           = 0555,
281                 .child          = debug_table,
282         },
283         {
284                 .procname       = "dev",
285                 .mode           = 0555,
286                 .child          = dev_table,
287         },
288         { }
289 };
290
291 #ifdef CONFIG_SCHED_DEBUG
292 static int min_sched_granularity_ns = 100000;           /* 100 usecs */
293 static int max_sched_granularity_ns = NSEC_PER_SEC;     /* 1 second */
294 static int min_wakeup_granularity_ns;                   /* 0 usecs */
295 static int max_wakeup_granularity_ns = NSEC_PER_SEC;    /* 1 second */
296 #ifdef CONFIG_SMP
297 static int min_sched_tunable_scaling = SCHED_TUNABLESCALING_NONE;
298 static int max_sched_tunable_scaling = SCHED_TUNABLESCALING_END-1;
299 #endif /* CONFIG_SMP */
300 #endif /* CONFIG_SCHED_DEBUG */
301
302 #ifdef CONFIG_COMPACTION
303 static int min_extfrag_threshold;
304 static int max_extfrag_threshold = 1000;
305 #endif
306
307 static struct ctl_table kern_table[] = {
308         {
309                 .procname       = "sched_child_runs_first",
310                 .data           = &sysctl_sched_child_runs_first,
311                 .maxlen         = sizeof(unsigned int),
312                 .mode           = 0644,
313                 .proc_handler   = proc_dointvec,
314         },
315 #ifdef CONFIG_SCHED_DEBUG
316         {
317                 .procname       = "sched_min_granularity_ns",
318                 .data           = &sysctl_sched_min_granularity,
319                 .maxlen         = sizeof(unsigned int),
320                 .mode           = 0644,
321                 .proc_handler   = sched_proc_update_handler,
322                 .extra1         = &min_sched_granularity_ns,
323                 .extra2         = &max_sched_granularity_ns,
324         },
325         {
326                 .procname       = "sched_latency_ns",
327                 .data           = &sysctl_sched_latency,
328                 .maxlen         = sizeof(unsigned int),
329                 .mode           = 0644,
330                 .proc_handler   = sched_proc_update_handler,
331                 .extra1         = &min_sched_granularity_ns,
332                 .extra2         = &max_sched_granularity_ns,
333         },
334         {
335                 .procname       = "sched_wakeup_granularity_ns",
336                 .data           = &sysctl_sched_wakeup_granularity,
337                 .maxlen         = sizeof(unsigned int),
338                 .mode           = 0644,
339                 .proc_handler   = sched_proc_update_handler,
340                 .extra1         = &min_wakeup_granularity_ns,
341                 .extra2         = &max_wakeup_granularity_ns,
342         },
343 #ifdef CONFIG_SMP
344         {
345                 .procname       = "sched_tunable_scaling",
346                 .data           = &sysctl_sched_tunable_scaling,
347                 .maxlen         = sizeof(enum sched_tunable_scaling),
348                 .mode           = 0644,
349                 .proc_handler   = sched_proc_update_handler,
350                 .extra1         = &min_sched_tunable_scaling,
351                 .extra2         = &max_sched_tunable_scaling,
352         },
353         {
354                 .procname       = "sched_migration_cost_ns",
355                 .data           = &sysctl_sched_migration_cost,
356                 .maxlen         = sizeof(unsigned int),
357                 .mode           = 0644,
358                 .proc_handler   = proc_dointvec,
359         },
360         {
361                 .procname       = "sched_nr_migrate",
362                 .data           = &sysctl_sched_nr_migrate,
363                 .maxlen         = sizeof(unsigned int),
364                 .mode           = 0644,
365                 .proc_handler   = proc_dointvec,
366         },
367 #ifdef CONFIG_SCHEDSTATS
368         {
369                 .procname       = "sched_schedstats",
370                 .data           = NULL,
371                 .maxlen         = sizeof(unsigned int),
372                 .mode           = 0644,
373                 .proc_handler   = sysctl_schedstats,
374                 .extra1         = SYSCTL_ZERO,
375                 .extra2         = SYSCTL_ONE,
376         },
377 #endif /* CONFIG_SCHEDSTATS */
378 #endif /* CONFIG_SMP */
379 #ifdef CONFIG_NUMA_BALANCING
380         {
381                 .procname       = "numa_balancing_scan_delay_ms",
382                 .data           = &sysctl_numa_balancing_scan_delay,
383                 .maxlen         = sizeof(unsigned int),
384                 .mode           = 0644,
385                 .proc_handler   = proc_dointvec,
386         },
387         {
388                 .procname       = "numa_balancing_scan_period_min_ms",
389                 .data           = &sysctl_numa_balancing_scan_period_min,
390                 .maxlen         = sizeof(unsigned int),
391                 .mode           = 0644,
392                 .proc_handler   = proc_dointvec,
393         },
394         {
395                 .procname       = "numa_balancing_scan_period_max_ms",
396                 .data           = &sysctl_numa_balancing_scan_period_max,
397                 .maxlen         = sizeof(unsigned int),
398                 .mode           = 0644,
399                 .proc_handler   = proc_dointvec,
400         },
401         {
402                 .procname       = "numa_balancing_scan_size_mb",
403                 .data           = &sysctl_numa_balancing_scan_size,
404                 .maxlen         = sizeof(unsigned int),
405                 .mode           = 0644,
406                 .proc_handler   = proc_dointvec_minmax,
407                 .extra1         = SYSCTL_ONE,
408         },
409         {
410                 .procname       = "numa_balancing",
411                 .data           = NULL, /* filled in by handler */
412                 .maxlen         = sizeof(unsigned int),
413                 .mode           = 0644,
414                 .proc_handler   = sysctl_numa_balancing,
415                 .extra1         = SYSCTL_ZERO,
416                 .extra2         = SYSCTL_ONE,
417         },
418 #endif /* CONFIG_NUMA_BALANCING */
419 #endif /* CONFIG_SCHED_DEBUG */
420         {
421                 .procname       = "sched_rt_period_us",
422                 .data           = &sysctl_sched_rt_period,
423                 .maxlen         = sizeof(unsigned int),
424                 .mode           = 0644,
425                 .proc_handler   = sched_rt_handler,
426         },
427         {
428                 .procname       = "sched_rt_runtime_us",
429                 .data           = &sysctl_sched_rt_runtime,
430                 .maxlen         = sizeof(int),
431                 .mode           = 0644,
432                 .proc_handler   = sched_rt_handler,
433         },
434         {
435                 .procname       = "sched_rr_timeslice_ms",
436                 .data           = &sysctl_sched_rr_timeslice,
437                 .maxlen         = sizeof(int),
438                 .mode           = 0644,
439                 .proc_handler   = sched_rr_handler,
440         },
441 #ifdef CONFIG_UCLAMP_TASK
442         {
443                 .procname       = "sched_util_clamp_min",
444                 .data           = &sysctl_sched_uclamp_util_min,
445                 .maxlen         = sizeof(unsigned int),
446                 .mode           = 0644,
447                 .proc_handler   = sysctl_sched_uclamp_handler,
448         },
449         {
450                 .procname       = "sched_util_clamp_max",
451                 .data           = &sysctl_sched_uclamp_util_max,
452                 .maxlen         = sizeof(unsigned int),
453                 .mode           = 0644,
454                 .proc_handler   = sysctl_sched_uclamp_handler,
455         },
456 #endif
457 #ifdef CONFIG_SCHED_AUTOGROUP
458         {
459                 .procname       = "sched_autogroup_enabled",
460                 .data           = &sysctl_sched_autogroup_enabled,
461                 .maxlen         = sizeof(unsigned int),
462                 .mode           = 0644,
463                 .proc_handler   = proc_dointvec_minmax,
464                 .extra1         = SYSCTL_ZERO,
465                 .extra2         = SYSCTL_ONE,
466         },
467 #endif
468 #ifdef CONFIG_CFS_BANDWIDTH
469         {
470                 .procname       = "sched_cfs_bandwidth_slice_us",
471                 .data           = &sysctl_sched_cfs_bandwidth_slice,
472                 .maxlen         = sizeof(unsigned int),
473                 .mode           = 0644,
474                 .proc_handler   = proc_dointvec_minmax,
475                 .extra1         = SYSCTL_ONE,
476         },
477 #endif
478 #if defined(CONFIG_ENERGY_MODEL) && defined(CONFIG_CPU_FREQ_GOV_SCHEDUTIL)
479         {
480                 .procname       = "sched_energy_aware",
481                 .data           = &sysctl_sched_energy_aware,
482                 .maxlen         = sizeof(unsigned int),
483                 .mode           = 0644,
484                 .proc_handler   = sched_energy_aware_handler,
485                 .extra1         = SYSCTL_ZERO,
486                 .extra2         = SYSCTL_ONE,
487         },
488 #endif
489 #ifdef CONFIG_PROVE_LOCKING
490         {
491                 .procname       = "prove_locking",
492                 .data           = &prove_locking,
493                 .maxlen         = sizeof(int),
494                 .mode           = 0644,
495                 .proc_handler   = proc_dointvec,
496         },
497 #endif
498 #ifdef CONFIG_LOCK_STAT
499         {
500                 .procname       = "lock_stat",
501                 .data           = &lock_stat,
502                 .maxlen         = sizeof(int),
503                 .mode           = 0644,
504                 .proc_handler   = proc_dointvec,
505         },
506 #endif
507         {
508                 .procname       = "panic",
509                 .data           = &panic_timeout,
510                 .maxlen         = sizeof(int),
511                 .mode           = 0644,
512                 .proc_handler   = proc_dointvec,
513         },
514 #ifdef CONFIG_COREDUMP
515         {
516                 .procname       = "core_uses_pid",
517                 .data           = &core_uses_pid,
518                 .maxlen         = sizeof(int),
519                 .mode           = 0644,
520                 .proc_handler   = proc_dointvec,
521         },
522         {
523                 .procname       = "core_pattern",
524                 .data           = core_pattern,
525                 .maxlen         = CORENAME_MAX_SIZE,
526                 .mode           = 0644,
527                 .proc_handler   = proc_dostring_coredump,
528         },
529         {
530                 .procname       = "core_pipe_limit",
531                 .data           = &core_pipe_limit,
532                 .maxlen         = sizeof(unsigned int),
533                 .mode           = 0644,
534                 .proc_handler   = proc_dointvec,
535         },
536 #endif
537 #ifdef CONFIG_PROC_SYSCTL
538         {
539                 .procname       = "tainted",
540                 .maxlen         = sizeof(long),
541                 .mode           = 0644,
542                 .proc_handler   = proc_taint,
543         },
544         {
545                 .procname       = "sysctl_writes_strict",
546                 .data           = &sysctl_writes_strict,
547                 .maxlen         = sizeof(int),
548                 .mode           = 0644,
549                 .proc_handler   = proc_dointvec_minmax,
550                 .extra1         = &neg_one,
551                 .extra2         = SYSCTL_ONE,
552         },
553 #endif
554 #ifdef CONFIG_LATENCYTOP
555         {
556                 .procname       = "latencytop",
557                 .data           = &latencytop_enabled,
558                 .maxlen         = sizeof(int),
559                 .mode           = 0644,
560                 .proc_handler   = sysctl_latencytop,
561         },
562 #endif
563 #ifdef CONFIG_BLK_DEV_INITRD
564         {
565                 .procname       = "real-root-dev",
566                 .data           = &real_root_dev,
567                 .maxlen         = sizeof(int),
568                 .mode           = 0644,
569                 .proc_handler   = proc_dointvec,
570         },
571 #endif
572         {
573                 .procname       = "print-fatal-signals",
574                 .data           = &print_fatal_signals,
575                 .maxlen         = sizeof(int),
576                 .mode           = 0644,
577                 .proc_handler   = proc_dointvec,
578         },
579 #ifdef CONFIG_SPARC
580         {
581                 .procname       = "reboot-cmd",
582                 .data           = reboot_command,
583                 .maxlen         = 256,
584                 .mode           = 0644,
585                 .proc_handler   = proc_dostring,
586         },
587         {
588                 .procname       = "stop-a",
589                 .data           = &stop_a_enabled,
590                 .maxlen         = sizeof (int),
591                 .mode           = 0644,
592                 .proc_handler   = proc_dointvec,
593         },
594         {
595                 .procname       = "scons-poweroff",
596                 .data           = &scons_pwroff,
597                 .maxlen         = sizeof (int),
598                 .mode           = 0644,
599                 .proc_handler   = proc_dointvec,
600         },
601 #endif
602 #ifdef CONFIG_SPARC64
603         {
604                 .procname       = "tsb-ratio",
605                 .data           = &sysctl_tsb_ratio,
606                 .maxlen         = sizeof (int),
607                 .mode           = 0644,
608                 .proc_handler   = proc_dointvec,
609         },
610 #endif
611 #ifdef CONFIG_PARISC
612         {
613                 .procname       = "soft-power",
614                 .data           = &pwrsw_enabled,
615                 .maxlen         = sizeof (int),
616                 .mode           = 0644,
617                 .proc_handler   = proc_dointvec,
618         },
619 #endif
620 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW
621         {
622                 .procname       = "unaligned-trap",
623                 .data           = &unaligned_enabled,
624                 .maxlen         = sizeof (int),
625                 .mode           = 0644,
626                 .proc_handler   = proc_dointvec,
627         },
628 #endif
629         {
630                 .procname       = "ctrl-alt-del",
631                 .data           = &C_A_D,
632                 .maxlen         = sizeof(int),
633                 .mode           = 0644,
634                 .proc_handler   = proc_dointvec,
635         },
636 #ifdef CONFIG_FUNCTION_TRACER
637         {
638                 .procname       = "ftrace_enabled",
639                 .data           = &ftrace_enabled,
640                 .maxlen         = sizeof(int),
641                 .mode           = 0644,
642                 .proc_handler   = ftrace_enable_sysctl,
643         },
644 #endif
645 #ifdef CONFIG_STACK_TRACER
646         {
647                 .procname       = "stack_tracer_enabled",
648                 .data           = &stack_tracer_enabled,
649                 .maxlen         = sizeof(int),
650                 .mode           = 0644,
651                 .proc_handler   = stack_trace_sysctl,
652         },
653 #endif
654 #ifdef CONFIG_TRACING
655         {
656                 .procname       = "ftrace_dump_on_oops",
657                 .data           = &ftrace_dump_on_oops,
658                 .maxlen         = sizeof(int),
659                 .mode           = 0644,
660                 .proc_handler   = proc_dointvec,
661         },
662         {
663                 .procname       = "traceoff_on_warning",
664                 .data           = &__disable_trace_on_warning,
665                 .maxlen         = sizeof(__disable_trace_on_warning),
666                 .mode           = 0644,
667                 .proc_handler   = proc_dointvec,
668         },
669         {
670                 .procname       = "tracepoint_printk",
671                 .data           = &tracepoint_printk,
672                 .maxlen         = sizeof(tracepoint_printk),
673                 .mode           = 0644,
674                 .proc_handler   = tracepoint_printk_sysctl,
675         },
676 #endif
677 #ifdef CONFIG_KEXEC_CORE
678         {
679                 .procname       = "kexec_load_disabled",
680                 .data           = &kexec_load_disabled,
681                 .maxlen         = sizeof(int),
682                 .mode           = 0644,
683                 /* only handle a transition from default "0" to "1" */
684                 .proc_handler   = proc_dointvec_minmax,
685                 .extra1         = SYSCTL_ONE,
686                 .extra2         = SYSCTL_ONE,
687         },
688 #endif
689 #ifdef CONFIG_MODULES
690         {
691                 .procname       = "modprobe",
692                 .data           = &modprobe_path,
693                 .maxlen         = KMOD_PATH_LEN,
694                 .mode           = 0644,
695                 .proc_handler   = proc_dostring,
696         },
697         {
698                 .procname       = "modules_disabled",
699                 .data           = &modules_disabled,
700                 .maxlen         = sizeof(int),
701                 .mode           = 0644,
702                 /* only handle a transition from default "0" to "1" */
703                 .proc_handler   = proc_dointvec_minmax,
704                 .extra1         = SYSCTL_ONE,
705                 .extra2         = SYSCTL_ONE,
706         },
707 #endif
708 #ifdef CONFIG_UEVENT_HELPER
709         {
710                 .procname       = "hotplug",
711                 .data           = &uevent_helper,
712                 .maxlen         = UEVENT_HELPER_PATH_LEN,
713                 .mode           = 0644,
714                 .proc_handler   = proc_dostring,
715         },
716 #endif
717 #ifdef CONFIG_CHR_DEV_SG
718         {
719                 .procname       = "sg-big-buff",
720                 .data           = &sg_big_buff,
721                 .maxlen         = sizeof (int),
722                 .mode           = 0444,
723                 .proc_handler   = proc_dointvec,
724         },
725 #endif
726 #ifdef CONFIG_BSD_PROCESS_ACCT
727         {
728                 .procname       = "acct",
729                 .data           = &acct_parm,
730                 .maxlen         = 3*sizeof(int),
731                 .mode           = 0644,
732                 .proc_handler   = proc_dointvec,
733         },
734 #endif
735 #ifdef CONFIG_MAGIC_SYSRQ
736         {
737                 .procname       = "sysrq",
738                 .data           = NULL,
739                 .maxlen         = sizeof (int),
740                 .mode           = 0644,
741                 .proc_handler   = sysrq_sysctl_handler,
742         },
743 #endif
744 #ifdef CONFIG_PROC_SYSCTL
745         {
746                 .procname       = "cad_pid",
747                 .data           = NULL,
748                 .maxlen         = sizeof (int),
749                 .mode           = 0600,
750                 .proc_handler   = proc_do_cad_pid,
751         },
752 #endif
753         {
754                 .procname       = "threads-max",
755                 .data           = NULL,
756                 .maxlen         = sizeof(int),
757                 .mode           = 0644,
758                 .proc_handler   = sysctl_max_threads,
759         },
760         {
761                 .procname       = "random",
762                 .mode           = 0555,
763                 .child          = random_table,
764         },
765         {
766                 .procname       = "usermodehelper",
767                 .mode           = 0555,
768                 .child          = usermodehelper_table,
769         },
770 #ifdef CONFIG_FW_LOADER_USER_HELPER
771         {
772                 .procname       = "firmware_config",
773                 .mode           = 0555,
774                 .child          = firmware_config_table,
775         },
776 #endif
777         {
778                 .procname       = "overflowuid",
779                 .data           = &overflowuid,
780                 .maxlen         = sizeof(int),
781                 .mode           = 0644,
782                 .proc_handler   = proc_dointvec_minmax,
783                 .extra1         = &minolduid,
784                 .extra2         = &maxolduid,
785         },
786         {
787                 .procname       = "overflowgid",
788                 .data           = &overflowgid,
789                 .maxlen         = sizeof(int),
790                 .mode           = 0644,
791                 .proc_handler   = proc_dointvec_minmax,
792                 .extra1         = &minolduid,
793                 .extra2         = &maxolduid,
794         },
795 #ifdef CONFIG_S390
796         {
797                 .procname       = "userprocess_debug",
798                 .data           = &show_unhandled_signals,
799                 .maxlen         = sizeof(int),
800                 .mode           = 0644,
801                 .proc_handler   = proc_dointvec,
802         },
803 #endif
804         {
805                 .procname       = "pid_max",
806                 .data           = &pid_max,
807                 .maxlen         = sizeof (int),
808                 .mode           = 0644,
809                 .proc_handler   = proc_dointvec_minmax,
810                 .extra1         = &pid_max_min,
811                 .extra2         = &pid_max_max,
812         },
813         {
814                 .procname       = "panic_on_oops",
815                 .data           = &panic_on_oops,
816                 .maxlen         = sizeof(int),
817                 .mode           = 0644,
818                 .proc_handler   = proc_dointvec,
819         },
820         {
821                 .procname       = "panic_print",
822                 .data           = &panic_print,
823                 .maxlen         = sizeof(unsigned long),
824                 .mode           = 0644,
825                 .proc_handler   = proc_doulongvec_minmax,
826         },
827 #if defined CONFIG_PRINTK
828         {
829                 .procname       = "printk",
830                 .data           = &console_loglevel,
831                 .maxlen         = 4*sizeof(int),
832                 .mode           = 0644,
833                 .proc_handler   = proc_dointvec,
834         },
835         {
836                 .procname       = "printk_ratelimit",
837                 .data           = &printk_ratelimit_state.interval,
838                 .maxlen         = sizeof(int),
839                 .mode           = 0644,
840                 .proc_handler   = proc_dointvec_jiffies,
841         },
842         {
843                 .procname       = "printk_ratelimit_burst",
844                 .data           = &printk_ratelimit_state.burst,
845                 .maxlen         = sizeof(int),
846                 .mode           = 0644,
847                 .proc_handler   = proc_dointvec,
848         },
849         {
850                 .procname       = "printk_delay",
851                 .data           = &printk_delay_msec,
852                 .maxlen         = sizeof(int),
853                 .mode           = 0644,
854                 .proc_handler   = proc_dointvec_minmax,
855                 .extra1         = SYSCTL_ZERO,
856                 .extra2         = &ten_thousand,
857         },
858         {
859                 .procname       = "printk_devkmsg",
860                 .data           = devkmsg_log_str,
861                 .maxlen         = DEVKMSG_STR_MAX_SIZE,
862                 .mode           = 0644,
863                 .proc_handler   = devkmsg_sysctl_set_loglvl,
864         },
865         {
866                 .procname       = "dmesg_restrict",
867                 .data           = &dmesg_restrict,
868                 .maxlen         = sizeof(int),
869                 .mode           = 0644,
870                 .proc_handler   = proc_dointvec_minmax_sysadmin,
871                 .extra1         = SYSCTL_ZERO,
872                 .extra2         = SYSCTL_ONE,
873         },
874         {
875                 .procname       = "kptr_restrict",
876                 .data           = &kptr_restrict,
877                 .maxlen         = sizeof(int),
878                 .mode           = 0644,
879                 .proc_handler   = proc_dointvec_minmax_sysadmin,
880                 .extra1         = SYSCTL_ZERO,
881                 .extra2         = &two,
882         },
883 #endif
884         {
885                 .procname       = "ngroups_max",
886                 .data           = &ngroups_max,
887                 .maxlen         = sizeof (int),
888                 .mode           = 0444,
889                 .proc_handler   = proc_dointvec,
890         },
891         {
892                 .procname       = "cap_last_cap",
893                 .data           = (void *)&cap_last_cap,
894                 .maxlen         = sizeof(int),
895                 .mode           = 0444,
896                 .proc_handler   = proc_dointvec,
897         },
898 #if defined(CONFIG_LOCKUP_DETECTOR)
899         {
900                 .procname       = "watchdog",
901                 .data           = &watchdog_user_enabled,
902                 .maxlen         = sizeof(int),
903                 .mode           = 0644,
904                 .proc_handler   = proc_watchdog,
905                 .extra1         = SYSCTL_ZERO,
906                 .extra2         = SYSCTL_ONE,
907         },
908         {
909                 .procname       = "watchdog_thresh",
910                 .data           = &watchdog_thresh,
911                 .maxlen         = sizeof(int),
912                 .mode           = 0644,
913                 .proc_handler   = proc_watchdog_thresh,
914                 .extra1         = SYSCTL_ZERO,
915                 .extra2         = &sixty,
916         },
917         {
918                 .procname       = "nmi_watchdog",
919                 .data           = &nmi_watchdog_user_enabled,
920                 .maxlen         = sizeof(int),
921                 .mode           = NMI_WATCHDOG_SYSCTL_PERM,
922                 .proc_handler   = proc_nmi_watchdog,
923                 .extra1         = SYSCTL_ZERO,
924                 .extra2         = SYSCTL_ONE,
925         },
926         {
927                 .procname       = "watchdog_cpumask",
928                 .data           = &watchdog_cpumask_bits,
929                 .maxlen         = NR_CPUS,
930                 .mode           = 0644,
931                 .proc_handler   = proc_watchdog_cpumask,
932         },
933 #ifdef CONFIG_SOFTLOCKUP_DETECTOR
934         {
935                 .procname       = "soft_watchdog",
936                 .data           = &soft_watchdog_user_enabled,
937                 .maxlen         = sizeof(int),
938                 .mode           = 0644,
939                 .proc_handler   = proc_soft_watchdog,
940                 .extra1         = SYSCTL_ZERO,
941                 .extra2         = SYSCTL_ONE,
942         },
943         {
944                 .procname       = "softlockup_panic",
945                 .data           = &softlockup_panic,
946                 .maxlen         = sizeof(int),
947                 .mode           = 0644,
948                 .proc_handler   = proc_dointvec_minmax,
949                 .extra1         = SYSCTL_ZERO,
950                 .extra2         = SYSCTL_ONE,
951         },
952 #ifdef CONFIG_SMP
953         {
954                 .procname       = "softlockup_all_cpu_backtrace",
955                 .data           = &sysctl_softlockup_all_cpu_backtrace,
956                 .maxlen         = sizeof(int),
957                 .mode           = 0644,
958                 .proc_handler   = proc_dointvec_minmax,
959                 .extra1         = SYSCTL_ZERO,
960                 .extra2         = SYSCTL_ONE,
961         },
962 #endif /* CONFIG_SMP */
963 #endif
964 #ifdef CONFIG_HARDLOCKUP_DETECTOR
965         {
966                 .procname       = "hardlockup_panic",
967                 .data           = &hardlockup_panic,
968                 .maxlen         = sizeof(int),
969                 .mode           = 0644,
970                 .proc_handler   = proc_dointvec_minmax,
971                 .extra1         = SYSCTL_ZERO,
972                 .extra2         = SYSCTL_ONE,
973         },
974 #ifdef CONFIG_SMP
975         {
976                 .procname       = "hardlockup_all_cpu_backtrace",
977                 .data           = &sysctl_hardlockup_all_cpu_backtrace,
978                 .maxlen         = sizeof(int),
979                 .mode           = 0644,
980                 .proc_handler   = proc_dointvec_minmax,
981                 .extra1         = SYSCTL_ZERO,
982                 .extra2         = SYSCTL_ONE,
983         },
984 #endif /* CONFIG_SMP */
985 #endif
986 #endif
987
988 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86)
989         {
990                 .procname       = "unknown_nmi_panic",
991                 .data           = &unknown_nmi_panic,
992                 .maxlen         = sizeof (int),
993                 .mode           = 0644,
994                 .proc_handler   = proc_dointvec,
995         },
996 #endif
997 #if defined(CONFIG_X86)
998         {
999                 .procname       = "panic_on_unrecovered_nmi",
1000                 .data           = &panic_on_unrecovered_nmi,
1001                 .maxlen         = sizeof(int),
1002                 .mode           = 0644,
1003                 .proc_handler   = proc_dointvec,
1004         },
1005         {
1006                 .procname       = "panic_on_io_nmi",
1007                 .data           = &panic_on_io_nmi,
1008                 .maxlen         = sizeof(int),
1009                 .mode           = 0644,
1010                 .proc_handler   = proc_dointvec,
1011         },
1012 #ifdef CONFIG_DEBUG_STACKOVERFLOW
1013         {
1014                 .procname       = "panic_on_stackoverflow",
1015                 .data           = &sysctl_panic_on_stackoverflow,
1016                 .maxlen         = sizeof(int),
1017                 .mode           = 0644,
1018                 .proc_handler   = proc_dointvec,
1019         },
1020 #endif
1021         {
1022                 .procname       = "bootloader_type",
1023                 .data           = &bootloader_type,
1024                 .maxlen         = sizeof (int),
1025                 .mode           = 0444,
1026                 .proc_handler   = proc_dointvec,
1027         },
1028         {
1029                 .procname       = "bootloader_version",
1030                 .data           = &bootloader_version,
1031                 .maxlen         = sizeof (int),
1032                 .mode           = 0444,
1033                 .proc_handler   = proc_dointvec,
1034         },
1035         {
1036                 .procname       = "io_delay_type",
1037                 .data           = &io_delay_type,
1038                 .maxlen         = sizeof(int),
1039                 .mode           = 0644,
1040                 .proc_handler   = proc_dointvec,
1041         },
1042 #endif
1043 #if defined(CONFIG_MMU)
1044         {
1045                 .procname       = "randomize_va_space",
1046                 .data           = &randomize_va_space,
1047                 .maxlen         = sizeof(int),
1048                 .mode           = 0644,
1049                 .proc_handler   = proc_dointvec,
1050         },
1051 #endif
1052 #if defined(CONFIG_S390) && defined(CONFIG_SMP)
1053         {
1054                 .procname       = "spin_retry",
1055                 .data           = &spin_retry,
1056                 .maxlen         = sizeof (int),
1057                 .mode           = 0644,
1058                 .proc_handler   = proc_dointvec,
1059         },
1060 #endif
1061 #if     defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86)
1062         {
1063                 .procname       = "acpi_video_flags",
1064                 .data           = &acpi_realmode_flags,
1065                 .maxlen         = sizeof (unsigned long),
1066                 .mode           = 0644,
1067                 .proc_handler   = proc_doulongvec_minmax,
1068         },
1069 #endif
1070 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN
1071         {
1072                 .procname       = "ignore-unaligned-usertrap",
1073                 .data           = &no_unaligned_warning,
1074                 .maxlen         = sizeof (int),
1075                 .mode           = 0644,
1076                 .proc_handler   = proc_dointvec,
1077         },
1078 #endif
1079 #ifdef CONFIG_IA64
1080         {
1081                 .procname       = "unaligned-dump-stack",
1082                 .data           = &unaligned_dump_stack,
1083                 .maxlen         = sizeof (int),
1084                 .mode           = 0644,
1085                 .proc_handler   = proc_dointvec,
1086         },
1087 #endif
1088 #ifdef CONFIG_DETECT_HUNG_TASK
1089         {
1090                 .procname       = "hung_task_panic",
1091                 .data           = &sysctl_hung_task_panic,
1092                 .maxlen         = sizeof(int),
1093                 .mode           = 0644,
1094                 .proc_handler   = proc_dointvec_minmax,
1095                 .extra1         = SYSCTL_ZERO,
1096                 .extra2         = SYSCTL_ONE,
1097         },
1098         {
1099                 .procname       = "hung_task_check_count",
1100                 .data           = &sysctl_hung_task_check_count,
1101                 .maxlen         = sizeof(int),
1102                 .mode           = 0644,
1103                 .proc_handler   = proc_dointvec_minmax,
1104                 .extra1         = SYSCTL_ZERO,
1105         },
1106         {
1107                 .procname       = "hung_task_timeout_secs",
1108                 .data           = &sysctl_hung_task_timeout_secs,
1109                 .maxlen         = sizeof(unsigned long),
1110                 .mode           = 0644,
1111                 .proc_handler   = proc_dohung_task_timeout_secs,
1112                 .extra2         = &hung_task_timeout_max,
1113         },
1114         {
1115                 .procname       = "hung_task_check_interval_secs",
1116                 .data           = &sysctl_hung_task_check_interval_secs,
1117                 .maxlen         = sizeof(unsigned long),
1118                 .mode           = 0644,
1119                 .proc_handler   = proc_dohung_task_timeout_secs,
1120                 .extra2         = &hung_task_timeout_max,
1121         },
1122         {
1123                 .procname       = "hung_task_warnings",
1124                 .data           = &sysctl_hung_task_warnings,
1125                 .maxlen         = sizeof(int),
1126                 .mode           = 0644,
1127                 .proc_handler   = proc_dointvec_minmax,
1128                 .extra1         = &neg_one,
1129         },
1130 #endif
1131 #ifdef CONFIG_RT_MUTEXES
1132         {
1133                 .procname       = "max_lock_depth",
1134                 .data           = &max_lock_depth,
1135                 .maxlen         = sizeof(int),
1136                 .mode           = 0644,
1137                 .proc_handler   = proc_dointvec,
1138         },
1139 #endif
1140         {
1141                 .procname       = "poweroff_cmd",
1142                 .data           = &poweroff_cmd,
1143                 .maxlen         = POWEROFF_CMD_PATH_LEN,
1144                 .mode           = 0644,
1145                 .proc_handler   = proc_dostring,
1146         },
1147 #ifdef CONFIG_KEYS
1148         {
1149                 .procname       = "keys",
1150                 .mode           = 0555,
1151                 .child          = key_sysctls,
1152         },
1153 #endif
1154 #ifdef CONFIG_PERF_EVENTS
1155         /*
1156          * User-space scripts rely on the existence of this file
1157          * as a feature check for perf_events being enabled.
1158          *
1159          * So it's an ABI, do not remove!
1160          */
1161         {
1162                 .procname       = "perf_event_paranoid",
1163                 .data           = &sysctl_perf_event_paranoid,
1164                 .maxlen         = sizeof(sysctl_perf_event_paranoid),
1165                 .mode           = 0644,
1166                 .proc_handler   = proc_dointvec,
1167         },
1168         {
1169                 .procname       = "perf_event_mlock_kb",
1170                 .data           = &sysctl_perf_event_mlock,
1171                 .maxlen         = sizeof(sysctl_perf_event_mlock),
1172                 .mode           = 0644,
1173                 .proc_handler   = proc_dointvec,
1174         },
1175         {
1176                 .procname       = "perf_event_max_sample_rate",
1177                 .data           = &sysctl_perf_event_sample_rate,
1178                 .maxlen         = sizeof(sysctl_perf_event_sample_rate),
1179                 .mode           = 0644,
1180                 .proc_handler   = perf_proc_update_handler,
1181                 .extra1         = SYSCTL_ONE,
1182         },
1183         {
1184                 .procname       = "perf_cpu_time_max_percent",
1185                 .data           = &sysctl_perf_cpu_time_max_percent,
1186                 .maxlen         = sizeof(sysctl_perf_cpu_time_max_percent),
1187                 .mode           = 0644,
1188                 .proc_handler   = perf_cpu_time_max_percent_handler,
1189                 .extra1         = SYSCTL_ZERO,
1190                 .extra2         = &one_hundred,
1191         },
1192         {
1193                 .procname       = "perf_event_max_stack",
1194                 .data           = &sysctl_perf_event_max_stack,
1195                 .maxlen         = sizeof(sysctl_perf_event_max_stack),
1196                 .mode           = 0644,
1197                 .proc_handler   = perf_event_max_stack_handler,
1198                 .extra1         = SYSCTL_ZERO,
1199                 .extra2         = &six_hundred_forty_kb,
1200         },
1201         {
1202                 .procname       = "perf_event_max_contexts_per_stack",
1203                 .data           = &sysctl_perf_event_max_contexts_per_stack,
1204                 .maxlen         = sizeof(sysctl_perf_event_max_contexts_per_stack),
1205                 .mode           = 0644,
1206                 .proc_handler   = perf_event_max_stack_handler,
1207                 .extra1         = SYSCTL_ZERO,
1208                 .extra2         = &one_thousand,
1209         },
1210 #endif
1211         {
1212                 .procname       = "panic_on_warn",
1213                 .data           = &panic_on_warn,
1214                 .maxlen         = sizeof(int),
1215                 .mode           = 0644,
1216                 .proc_handler   = proc_dointvec_minmax,
1217                 .extra1         = SYSCTL_ZERO,
1218                 .extra2         = SYSCTL_ONE,
1219         },
1220 #if defined(CONFIG_SMP) && defined(CONFIG_NO_HZ_COMMON)
1221         {
1222                 .procname       = "timer_migration",
1223                 .data           = &sysctl_timer_migration,
1224                 .maxlen         = sizeof(unsigned int),
1225                 .mode           = 0644,
1226                 .proc_handler   = timer_migration_handler,
1227                 .extra1         = SYSCTL_ZERO,
1228                 .extra2         = SYSCTL_ONE,
1229         },
1230 #endif
1231 #ifdef CONFIG_BPF_SYSCALL
1232         {
1233                 .procname       = "unprivileged_bpf_disabled",
1234                 .data           = &sysctl_unprivileged_bpf_disabled,
1235                 .maxlen         = sizeof(sysctl_unprivileged_bpf_disabled),
1236                 .mode           = 0644,
1237                 /* only handle a transition from default "0" to "1" */
1238                 .proc_handler   = proc_dointvec_minmax,
1239                 .extra1         = SYSCTL_ONE,
1240                 .extra2         = SYSCTL_ONE,
1241         },
1242         {
1243                 .procname       = "bpf_stats_enabled",
1244                 .data           = &bpf_stats_enabled_key.key,
1245                 .maxlen         = sizeof(bpf_stats_enabled_key),
1246                 .mode           = 0644,
1247                 .proc_handler   = proc_do_static_key,
1248         },
1249 #endif
1250 #if defined(CONFIG_TREE_RCU)
1251         {
1252                 .procname       = "panic_on_rcu_stall",
1253                 .data           = &sysctl_panic_on_rcu_stall,
1254                 .maxlen         = sizeof(sysctl_panic_on_rcu_stall),
1255                 .mode           = 0644,
1256                 .proc_handler   = proc_dointvec_minmax,
1257                 .extra1         = SYSCTL_ZERO,
1258                 .extra2         = SYSCTL_ONE,
1259         },
1260 #endif
1261 #ifdef CONFIG_STACKLEAK_RUNTIME_DISABLE
1262         {
1263                 .procname       = "stack_erasing",
1264                 .data           = NULL,
1265                 .maxlen         = sizeof(int),
1266                 .mode           = 0600,
1267                 .proc_handler   = stack_erasing_sysctl,
1268                 .extra1         = SYSCTL_ZERO,
1269                 .extra2         = SYSCTL_ONE,
1270         },
1271 #endif
1272         { }
1273 };
1274
1275 static struct ctl_table vm_table[] = {
1276         {
1277                 .procname       = "overcommit_memory",
1278                 .data           = &sysctl_overcommit_memory,
1279                 .maxlen         = sizeof(sysctl_overcommit_memory),
1280                 .mode           = 0644,
1281                 .proc_handler   = proc_dointvec_minmax,
1282                 .extra1         = SYSCTL_ZERO,
1283                 .extra2         = &two,
1284         },
1285         {
1286                 .procname       = "panic_on_oom",
1287                 .data           = &sysctl_panic_on_oom,
1288                 .maxlen         = sizeof(sysctl_panic_on_oom),
1289                 .mode           = 0644,
1290                 .proc_handler   = proc_dointvec_minmax,
1291                 .extra1         = SYSCTL_ZERO,
1292                 .extra2         = &two,
1293         },
1294         {
1295                 .procname       = "oom_kill_allocating_task",
1296                 .data           = &sysctl_oom_kill_allocating_task,
1297                 .maxlen         = sizeof(sysctl_oom_kill_allocating_task),
1298                 .mode           = 0644,
1299                 .proc_handler   = proc_dointvec,
1300         },
1301         {
1302                 .procname       = "oom_dump_tasks",
1303                 .data           = &sysctl_oom_dump_tasks,
1304                 .maxlen         = sizeof(sysctl_oom_dump_tasks),
1305                 .mode           = 0644,
1306                 .proc_handler   = proc_dointvec,
1307         },
1308         {
1309                 .procname       = "overcommit_ratio",
1310                 .data           = &sysctl_overcommit_ratio,
1311                 .maxlen         = sizeof(sysctl_overcommit_ratio),
1312                 .mode           = 0644,
1313                 .proc_handler   = overcommit_ratio_handler,
1314         },
1315         {
1316                 .procname       = "overcommit_kbytes",
1317                 .data           = &sysctl_overcommit_kbytes,
1318                 .maxlen         = sizeof(sysctl_overcommit_kbytes),
1319                 .mode           = 0644,
1320                 .proc_handler   = overcommit_kbytes_handler,
1321         },
1322         {
1323                 .procname       = "page-cluster", 
1324                 .data           = &page_cluster,
1325                 .maxlen         = sizeof(int),
1326                 .mode           = 0644,
1327                 .proc_handler   = proc_dointvec_minmax,
1328                 .extra1         = SYSCTL_ZERO,
1329         },
1330         {
1331                 .procname       = "dirty_background_ratio",
1332                 .data           = &dirty_background_ratio,
1333                 .maxlen         = sizeof(dirty_background_ratio),
1334                 .mode           = 0644,
1335                 .proc_handler   = dirty_background_ratio_handler,
1336                 .extra1         = SYSCTL_ZERO,
1337                 .extra2         = &one_hundred,
1338         },
1339         {
1340                 .procname       = "dirty_background_bytes",
1341                 .data           = &dirty_background_bytes,
1342                 .maxlen         = sizeof(dirty_background_bytes),
1343                 .mode           = 0644,
1344                 .proc_handler   = dirty_background_bytes_handler,
1345                 .extra1         = &one_ul,
1346         },
1347         {
1348                 .procname       = "dirty_ratio",
1349                 .data           = &vm_dirty_ratio,
1350                 .maxlen         = sizeof(vm_dirty_ratio),
1351                 .mode           = 0644,
1352                 .proc_handler   = dirty_ratio_handler,
1353                 .extra1         = SYSCTL_ZERO,
1354                 .extra2         = &one_hundred,
1355         },
1356         {
1357                 .procname       = "dirty_bytes",
1358                 .data           = &vm_dirty_bytes,
1359                 .maxlen         = sizeof(vm_dirty_bytes),
1360                 .mode           = 0644,
1361                 .proc_handler   = dirty_bytes_handler,
1362                 .extra1         = &dirty_bytes_min,
1363         },
1364         {
1365                 .procname       = "dirty_writeback_centisecs",
1366                 .data           = &dirty_writeback_interval,
1367                 .maxlen         = sizeof(dirty_writeback_interval),
1368                 .mode           = 0644,
1369                 .proc_handler   = dirty_writeback_centisecs_handler,
1370         },
1371         {
1372                 .procname       = "dirty_expire_centisecs",
1373                 .data           = &dirty_expire_interval,
1374                 .maxlen         = sizeof(dirty_expire_interval),
1375                 .mode           = 0644,
1376                 .proc_handler   = proc_dointvec_minmax,
1377                 .extra1         = SYSCTL_ZERO,
1378         },
1379         {
1380                 .procname       = "dirtytime_expire_seconds",
1381                 .data           = &dirtytime_expire_interval,
1382                 .maxlen         = sizeof(dirtytime_expire_interval),
1383                 .mode           = 0644,
1384                 .proc_handler   = dirtytime_interval_handler,
1385                 .extra1         = SYSCTL_ZERO,
1386         },
1387         {
1388                 .procname       = "swappiness",
1389                 .data           = &vm_swappiness,
1390                 .maxlen         = sizeof(vm_swappiness),
1391                 .mode           = 0644,
1392                 .proc_handler   = proc_dointvec_minmax,
1393                 .extra1         = SYSCTL_ZERO,
1394                 .extra2         = &one_hundred,
1395         },
1396 #ifdef CONFIG_HUGETLB_PAGE
1397         {
1398                 .procname       = "nr_hugepages",
1399                 .data           = NULL,
1400                 .maxlen         = sizeof(unsigned long),
1401                 .mode           = 0644,
1402                 .proc_handler   = hugetlb_sysctl_handler,
1403         },
1404 #ifdef CONFIG_NUMA
1405         {
1406                 .procname       = "nr_hugepages_mempolicy",
1407                 .data           = NULL,
1408                 .maxlen         = sizeof(unsigned long),
1409                 .mode           = 0644,
1410                 .proc_handler   = &hugetlb_mempolicy_sysctl_handler,
1411         },
1412         {
1413                 .procname               = "numa_stat",
1414                 .data                   = &sysctl_vm_numa_stat,
1415                 .maxlen                 = sizeof(int),
1416                 .mode                   = 0644,
1417                 .proc_handler   = sysctl_vm_numa_stat_handler,
1418                 .extra1                 = SYSCTL_ZERO,
1419                 .extra2                 = SYSCTL_ONE,
1420         },
1421 #endif
1422          {
1423                 .procname       = "hugetlb_shm_group",
1424                 .data           = &sysctl_hugetlb_shm_group,
1425                 .maxlen         = sizeof(gid_t),
1426                 .mode           = 0644,
1427                 .proc_handler   = proc_dointvec,
1428          },
1429         {
1430                 .procname       = "nr_overcommit_hugepages",
1431                 .data           = NULL,
1432                 .maxlen         = sizeof(unsigned long),
1433                 .mode           = 0644,
1434                 .proc_handler   = hugetlb_overcommit_handler,
1435         },
1436 #endif
1437         {
1438                 .procname       = "lowmem_reserve_ratio",
1439                 .data           = &sysctl_lowmem_reserve_ratio,
1440                 .maxlen         = sizeof(sysctl_lowmem_reserve_ratio),
1441                 .mode           = 0644,
1442                 .proc_handler   = lowmem_reserve_ratio_sysctl_handler,
1443         },
1444         {
1445                 .procname       = "drop_caches",
1446                 .data           = &sysctl_drop_caches,
1447                 .maxlen         = sizeof(int),
1448                 .mode           = 0200,
1449                 .proc_handler   = drop_caches_sysctl_handler,
1450                 .extra1         = SYSCTL_ONE,
1451                 .extra2         = &four,
1452         },
1453 #ifdef CONFIG_COMPACTION
1454         {
1455                 .procname       = "compact_memory",
1456                 .data           = &sysctl_compact_memory,
1457                 .maxlen         = sizeof(int),
1458                 .mode           = 0200,
1459                 .proc_handler   = sysctl_compaction_handler,
1460         },
1461         {
1462                 .procname       = "extfrag_threshold",
1463                 .data           = &sysctl_extfrag_threshold,
1464                 .maxlen         = sizeof(int),
1465                 .mode           = 0644,
1466                 .proc_handler   = proc_dointvec_minmax,
1467                 .extra1         = &min_extfrag_threshold,
1468                 .extra2         = &max_extfrag_threshold,
1469         },
1470         {
1471                 .procname       = "compact_unevictable_allowed",
1472                 .data           = &sysctl_compact_unevictable_allowed,
1473                 .maxlen         = sizeof(int),
1474                 .mode           = 0644,
1475                 .proc_handler   = proc_dointvec_minmax_warn_RT_change,
1476                 .extra1         = SYSCTL_ZERO,
1477                 .extra2         = SYSCTL_ONE,
1478         },
1479
1480 #endif /* CONFIG_COMPACTION */
1481         {
1482                 .procname       = "min_free_kbytes",
1483                 .data           = &min_free_kbytes,
1484                 .maxlen         = sizeof(min_free_kbytes),
1485                 .mode           = 0644,
1486                 .proc_handler   = min_free_kbytes_sysctl_handler,
1487                 .extra1         = SYSCTL_ZERO,
1488         },
1489         {
1490                 .procname       = "watermark_boost_factor",
1491                 .data           = &watermark_boost_factor,
1492                 .maxlen         = sizeof(watermark_boost_factor),
1493                 .mode           = 0644,
1494                 .proc_handler   = watermark_boost_factor_sysctl_handler,
1495                 .extra1         = SYSCTL_ZERO,
1496         },
1497         {
1498                 .procname       = "watermark_scale_factor",
1499                 .data           = &watermark_scale_factor,
1500                 .maxlen         = sizeof(watermark_scale_factor),
1501                 .mode           = 0644,
1502                 .proc_handler   = watermark_scale_factor_sysctl_handler,
1503                 .extra1         = SYSCTL_ONE,
1504                 .extra2         = &one_thousand,
1505         },
1506         {
1507                 .procname       = "percpu_pagelist_fraction",
1508                 .data           = &percpu_pagelist_fraction,
1509                 .maxlen         = sizeof(percpu_pagelist_fraction),
1510                 .mode           = 0644,
1511                 .proc_handler   = percpu_pagelist_fraction_sysctl_handler,
1512                 .extra1         = SYSCTL_ZERO,
1513         },
1514 #ifdef CONFIG_MMU
1515         {
1516                 .procname       = "max_map_count",
1517                 .data           = &sysctl_max_map_count,
1518                 .maxlen         = sizeof(sysctl_max_map_count),
1519                 .mode           = 0644,
1520                 .proc_handler   = proc_dointvec_minmax,
1521                 .extra1         = SYSCTL_ZERO,
1522         },
1523 #else
1524         {
1525                 .procname       = "nr_trim_pages",
1526                 .data           = &sysctl_nr_trim_pages,
1527                 .maxlen         = sizeof(sysctl_nr_trim_pages),
1528                 .mode           = 0644,
1529                 .proc_handler   = proc_dointvec_minmax,
1530                 .extra1         = SYSCTL_ZERO,
1531         },
1532 #endif
1533         {
1534                 .procname       = "laptop_mode",
1535                 .data           = &laptop_mode,
1536                 .maxlen         = sizeof(laptop_mode),
1537                 .mode           = 0644,
1538                 .proc_handler   = proc_dointvec_jiffies,
1539         },
1540         {
1541                 .procname       = "block_dump",
1542                 .data           = &block_dump,
1543                 .maxlen         = sizeof(block_dump),
1544                 .mode           = 0644,
1545                 .proc_handler   = proc_dointvec,
1546                 .extra1         = SYSCTL_ZERO,
1547         },
1548         {
1549                 .procname       = "vfs_cache_pressure",
1550                 .data           = &sysctl_vfs_cache_pressure,
1551                 .maxlen         = sizeof(sysctl_vfs_cache_pressure),
1552                 .mode           = 0644,
1553                 .proc_handler   = proc_dointvec,
1554                 .extra1         = SYSCTL_ZERO,
1555         },
1556 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \
1557     defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT)
1558         {
1559                 .procname       = "legacy_va_layout",
1560                 .data           = &sysctl_legacy_va_layout,
1561                 .maxlen         = sizeof(sysctl_legacy_va_layout),
1562                 .mode           = 0644,
1563                 .proc_handler   = proc_dointvec,
1564                 .extra1         = SYSCTL_ZERO,
1565         },
1566 #endif
1567 #ifdef CONFIG_NUMA
1568         {
1569                 .procname       = "zone_reclaim_mode",
1570                 .data           = &node_reclaim_mode,
1571                 .maxlen         = sizeof(node_reclaim_mode),
1572                 .mode           = 0644,
1573                 .proc_handler   = proc_dointvec,
1574                 .extra1         = SYSCTL_ZERO,
1575         },
1576         {
1577                 .procname       = "min_unmapped_ratio",
1578                 .data           = &sysctl_min_unmapped_ratio,
1579                 .maxlen         = sizeof(sysctl_min_unmapped_ratio),
1580                 .mode           = 0644,
1581                 .proc_handler   = sysctl_min_unmapped_ratio_sysctl_handler,
1582                 .extra1         = SYSCTL_ZERO,
1583                 .extra2         = &one_hundred,
1584         },
1585         {
1586                 .procname       = "min_slab_ratio",
1587                 .data           = &sysctl_min_slab_ratio,
1588                 .maxlen         = sizeof(sysctl_min_slab_ratio),
1589                 .mode           = 0644,
1590                 .proc_handler   = sysctl_min_slab_ratio_sysctl_handler,
1591                 .extra1         = SYSCTL_ZERO,
1592                 .extra2         = &one_hundred,
1593         },
1594 #endif
1595 #ifdef CONFIG_SMP
1596         {
1597                 .procname       = "stat_interval",
1598                 .data           = &sysctl_stat_interval,
1599                 .maxlen         = sizeof(sysctl_stat_interval),
1600                 .mode           = 0644,
1601                 .proc_handler   = proc_dointvec_jiffies,
1602         },
1603         {
1604                 .procname       = "stat_refresh",
1605                 .data           = NULL,
1606                 .maxlen         = 0,
1607                 .mode           = 0600,
1608                 .proc_handler   = vmstat_refresh,
1609         },
1610 #endif
1611 #ifdef CONFIG_MMU
1612         {
1613                 .procname       = "mmap_min_addr",
1614                 .data           = &dac_mmap_min_addr,
1615                 .maxlen         = sizeof(unsigned long),
1616                 .mode           = 0644,
1617                 .proc_handler   = mmap_min_addr_handler,
1618         },
1619 #endif
1620 #ifdef CONFIG_NUMA
1621         {
1622                 .procname       = "numa_zonelist_order",
1623                 .data           = &numa_zonelist_order,
1624                 .maxlen         = NUMA_ZONELIST_ORDER_LEN,
1625                 .mode           = 0644,
1626                 .proc_handler   = numa_zonelist_order_handler,
1627         },
1628 #endif
1629 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \
1630    (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL))
1631         {
1632                 .procname       = "vdso_enabled",
1633 #ifdef CONFIG_X86_32
1634                 .data           = &vdso32_enabled,
1635                 .maxlen         = sizeof(vdso32_enabled),
1636 #else
1637                 .data           = &vdso_enabled,
1638                 .maxlen         = sizeof(vdso_enabled),
1639 #endif
1640                 .mode           = 0644,
1641                 .proc_handler   = proc_dointvec,
1642                 .extra1         = SYSCTL_ZERO,
1643         },
1644 #endif
1645 #ifdef CONFIG_HIGHMEM
1646         {
1647                 .procname       = "highmem_is_dirtyable",
1648                 .data           = &vm_highmem_is_dirtyable,
1649                 .maxlen         = sizeof(vm_highmem_is_dirtyable),
1650                 .mode           = 0644,
1651                 .proc_handler   = proc_dointvec_minmax,
1652                 .extra1         = SYSCTL_ZERO,
1653                 .extra2         = SYSCTL_ONE,
1654         },
1655 #endif
1656 #ifdef CONFIG_MEMORY_FAILURE
1657         {
1658                 .procname       = "memory_failure_early_kill",
1659                 .data           = &sysctl_memory_failure_early_kill,
1660                 .maxlen         = sizeof(sysctl_memory_failure_early_kill),
1661                 .mode           = 0644,
1662                 .proc_handler   = proc_dointvec_minmax,
1663                 .extra1         = SYSCTL_ZERO,
1664                 .extra2         = SYSCTL_ONE,
1665         },
1666         {
1667                 .procname       = "memory_failure_recovery",
1668                 .data           = &sysctl_memory_failure_recovery,
1669                 .maxlen         = sizeof(sysctl_memory_failure_recovery),
1670                 .mode           = 0644,
1671                 .proc_handler   = proc_dointvec_minmax,
1672                 .extra1         = SYSCTL_ZERO,
1673                 .extra2         = SYSCTL_ONE,
1674         },
1675 #endif
1676         {
1677                 .procname       = "user_reserve_kbytes",
1678                 .data           = &sysctl_user_reserve_kbytes,
1679                 .maxlen         = sizeof(sysctl_user_reserve_kbytes),
1680                 .mode           = 0644,
1681                 .proc_handler   = proc_doulongvec_minmax,
1682         },
1683         {
1684                 .procname       = "admin_reserve_kbytes",
1685                 .data           = &sysctl_admin_reserve_kbytes,
1686                 .maxlen         = sizeof(sysctl_admin_reserve_kbytes),
1687                 .mode           = 0644,
1688                 .proc_handler   = proc_doulongvec_minmax,
1689         },
1690 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS
1691         {
1692                 .procname       = "mmap_rnd_bits",
1693                 .data           = &mmap_rnd_bits,
1694                 .maxlen         = sizeof(mmap_rnd_bits),
1695                 .mode           = 0600,
1696                 .proc_handler   = proc_dointvec_minmax,
1697                 .extra1         = (void *)&mmap_rnd_bits_min,
1698                 .extra2         = (void *)&mmap_rnd_bits_max,
1699         },
1700 #endif
1701 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS
1702         {
1703                 .procname       = "mmap_rnd_compat_bits",
1704                 .data           = &mmap_rnd_compat_bits,
1705                 .maxlen         = sizeof(mmap_rnd_compat_bits),
1706                 .mode           = 0600,
1707                 .proc_handler   = proc_dointvec_minmax,
1708                 .extra1         = (void *)&mmap_rnd_compat_bits_min,
1709                 .extra2         = (void *)&mmap_rnd_compat_bits_max,
1710         },
1711 #endif
1712 #ifdef CONFIG_USERFAULTFD
1713         {
1714                 .procname       = "unprivileged_userfaultfd",
1715                 .data           = &sysctl_unprivileged_userfaultfd,
1716                 .maxlen         = sizeof(sysctl_unprivileged_userfaultfd),
1717                 .mode           = 0644,
1718                 .proc_handler   = proc_dointvec_minmax,
1719                 .extra1         = SYSCTL_ZERO,
1720                 .extra2         = SYSCTL_ONE,
1721         },
1722 #endif
1723         { }
1724 };
1725
1726 static struct ctl_table fs_table[] = {
1727         {
1728                 .procname       = "inode-nr",
1729                 .data           = &inodes_stat,
1730                 .maxlen         = 2*sizeof(long),
1731                 .mode           = 0444,
1732                 .proc_handler   = proc_nr_inodes,
1733         },
1734         {
1735                 .procname       = "inode-state",
1736                 .data           = &inodes_stat,
1737                 .maxlen         = 7*sizeof(long),
1738                 .mode           = 0444,
1739                 .proc_handler   = proc_nr_inodes,
1740         },
1741         {
1742                 .procname       = "file-nr",
1743                 .data           = &files_stat,
1744                 .maxlen         = sizeof(files_stat),
1745                 .mode           = 0444,
1746                 .proc_handler   = proc_nr_files,
1747         },
1748         {
1749                 .procname       = "file-max",
1750                 .data           = &files_stat.max_files,
1751                 .maxlen         = sizeof(files_stat.max_files),
1752                 .mode           = 0644,
1753                 .proc_handler   = proc_doulongvec_minmax,
1754                 .extra1         = &zero_ul,
1755                 .extra2         = &long_max,
1756         },
1757         {
1758                 .procname       = "nr_open",
1759                 .data           = &sysctl_nr_open,
1760                 .maxlen         = sizeof(unsigned int),
1761                 .mode           = 0644,
1762                 .proc_handler   = proc_dointvec_minmax,
1763                 .extra1         = &sysctl_nr_open_min,
1764                 .extra2         = &sysctl_nr_open_max,
1765         },
1766         {
1767                 .procname       = "dentry-state",
1768                 .data           = &dentry_stat,
1769                 .maxlen         = 6*sizeof(long),
1770                 .mode           = 0444,
1771                 .proc_handler   = proc_nr_dentry,
1772         },
1773         {
1774                 .procname       = "overflowuid",
1775                 .data           = &fs_overflowuid,
1776                 .maxlen         = sizeof(int),
1777                 .mode           = 0644,
1778                 .proc_handler   = proc_dointvec_minmax,
1779                 .extra1         = &minolduid,
1780                 .extra2         = &maxolduid,
1781         },
1782         {
1783                 .procname       = "overflowgid",
1784                 .data           = &fs_overflowgid,
1785                 .maxlen         = sizeof(int),
1786                 .mode           = 0644,
1787                 .proc_handler   = proc_dointvec_minmax,
1788                 .extra1         = &minolduid,
1789                 .extra2         = &maxolduid,
1790         },
1791 #ifdef CONFIG_FILE_LOCKING
1792         {
1793                 .procname       = "leases-enable",
1794                 .data           = &leases_enable,
1795                 .maxlen         = sizeof(int),
1796                 .mode           = 0644,
1797                 .proc_handler   = proc_dointvec,
1798         },
1799 #endif
1800 #ifdef CONFIG_DNOTIFY
1801         {
1802                 .procname       = "dir-notify-enable",
1803                 .data           = &dir_notify_enable,
1804                 .maxlen         = sizeof(int),
1805                 .mode           = 0644,
1806                 .proc_handler   = proc_dointvec,
1807         },
1808 #endif
1809 #ifdef CONFIG_MMU
1810 #ifdef CONFIG_FILE_LOCKING
1811         {
1812                 .procname       = "lease-break-time",
1813                 .data           = &lease_break_time,
1814                 .maxlen         = sizeof(int),
1815                 .mode           = 0644,
1816                 .proc_handler   = proc_dointvec,
1817         },
1818 #endif
1819 #ifdef CONFIG_AIO
1820         {
1821                 .procname       = "aio-nr",
1822                 .data           = &aio_nr,
1823                 .maxlen         = sizeof(aio_nr),
1824                 .mode           = 0444,
1825                 .proc_handler   = proc_doulongvec_minmax,
1826         },
1827         {
1828                 .procname       = "aio-max-nr",
1829                 .data           = &aio_max_nr,
1830                 .maxlen         = sizeof(aio_max_nr),
1831                 .mode           = 0644,
1832                 .proc_handler   = proc_doulongvec_minmax,
1833         },
1834 #endif /* CONFIG_AIO */
1835 #ifdef CONFIG_INOTIFY_USER
1836         {
1837                 .procname       = "inotify",
1838                 .mode           = 0555,
1839                 .child          = inotify_table,
1840         },
1841 #endif  
1842 #ifdef CONFIG_EPOLL
1843         {
1844                 .procname       = "epoll",
1845                 .mode           = 0555,
1846                 .child          = epoll_table,
1847         },
1848 #endif
1849 #endif
1850         {
1851                 .procname       = "protected_symlinks",
1852                 .data           = &sysctl_protected_symlinks,
1853                 .maxlen         = sizeof(int),
1854                 .mode           = 0600,
1855                 .proc_handler   = proc_dointvec_minmax,
1856                 .extra1         = SYSCTL_ZERO,
1857                 .extra2         = SYSCTL_ONE,
1858         },
1859         {
1860                 .procname       = "protected_hardlinks",
1861                 .data           = &sysctl_protected_hardlinks,
1862                 .maxlen         = sizeof(int),
1863                 .mode           = 0600,
1864                 .proc_handler   = proc_dointvec_minmax,
1865                 .extra1         = SYSCTL_ZERO,
1866                 .extra2         = SYSCTL_ONE,
1867         },
1868         {
1869                 .procname       = "protected_fifos",
1870                 .data           = &sysctl_protected_fifos,
1871                 .maxlen         = sizeof(int),
1872                 .mode           = 0600,
1873                 .proc_handler   = proc_dointvec_minmax,
1874                 .extra1         = SYSCTL_ZERO,
1875                 .extra2         = &two,
1876         },
1877         {
1878                 .procname       = "protected_regular",
1879                 .data           = &sysctl_protected_regular,
1880                 .maxlen         = sizeof(int),
1881                 .mode           = 0600,
1882                 .proc_handler   = proc_dointvec_minmax,
1883                 .extra1         = SYSCTL_ZERO,
1884                 .extra2         = &two,
1885         },
1886         {
1887                 .procname       = "suid_dumpable",
1888                 .data           = &suid_dumpable,
1889                 .maxlen         = sizeof(int),
1890                 .mode           = 0644,
1891                 .proc_handler   = proc_dointvec_minmax_coredump,
1892                 .extra1         = SYSCTL_ZERO,
1893                 .extra2         = &two,
1894         },
1895 #if defined(CONFIG_BINFMT_MISC) || defined(CONFIG_BINFMT_MISC_MODULE)
1896         {
1897                 .procname       = "binfmt_misc",
1898                 .mode           = 0555,
1899                 .child          = sysctl_mount_point,
1900         },
1901 #endif
1902         {
1903                 .procname       = "pipe-max-size",
1904                 .data           = &pipe_max_size,
1905                 .maxlen         = sizeof(pipe_max_size),
1906                 .mode           = 0644,
1907                 .proc_handler   = proc_dopipe_max_size,
1908         },
1909         {
1910                 .procname       = "pipe-user-pages-hard",
1911                 .data           = &pipe_user_pages_hard,
1912                 .maxlen         = sizeof(pipe_user_pages_hard),
1913                 .mode           = 0644,
1914                 .proc_handler   = proc_doulongvec_minmax,
1915         },
1916         {
1917                 .procname       = "pipe-user-pages-soft",
1918                 .data           = &pipe_user_pages_soft,
1919                 .maxlen         = sizeof(pipe_user_pages_soft),
1920                 .mode           = 0644,
1921                 .proc_handler   = proc_doulongvec_minmax,
1922         },
1923         {
1924                 .procname       = "mount-max",
1925                 .data           = &sysctl_mount_max,
1926                 .maxlen         = sizeof(unsigned int),
1927                 .mode           = 0644,
1928                 .proc_handler   = proc_dointvec_minmax,
1929                 .extra1         = SYSCTL_ONE,
1930         },
1931         { }
1932 };
1933
1934 static struct ctl_table debug_table[] = {
1935 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE
1936         {
1937                 .procname       = "exception-trace",
1938                 .data           = &show_unhandled_signals,
1939                 .maxlen         = sizeof(int),
1940                 .mode           = 0644,
1941                 .proc_handler   = proc_dointvec
1942         },
1943 #endif
1944 #if defined(CONFIG_OPTPROBES)
1945         {
1946                 .procname       = "kprobes-optimization",
1947                 .data           = &sysctl_kprobes_optimization,
1948                 .maxlen         = sizeof(int),
1949                 .mode           = 0644,
1950                 .proc_handler   = proc_kprobes_optimization_handler,
1951                 .extra1         = SYSCTL_ZERO,
1952                 .extra2         = SYSCTL_ONE,
1953         },
1954 #endif
1955         { }
1956 };
1957
1958 static struct ctl_table dev_table[] = {
1959         { }
1960 };
1961
1962 int __init sysctl_init(void)
1963 {
1964         struct ctl_table_header *hdr;
1965
1966         hdr = register_sysctl_table(sysctl_base_table);
1967         kmemleak_not_leak(hdr);
1968         return 0;
1969 }
1970
1971 #endif /* CONFIG_SYSCTL */
1972
1973 /*
1974  * /proc/sys support
1975  */
1976
1977 #ifdef CONFIG_PROC_SYSCTL
1978
1979 static int _proc_do_string(char *data, int maxlen, int write,
1980                            char __user *buffer,
1981                            size_t *lenp, loff_t *ppos)
1982 {
1983         size_t len;
1984         char __user *p;
1985         char c;
1986
1987         if (!data || !maxlen || !*lenp) {
1988                 *lenp = 0;
1989                 return 0;
1990         }
1991
1992         if (write) {
1993                 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) {
1994                         /* Only continue writes not past the end of buffer. */
1995                         len = strlen(data);
1996                         if (len > maxlen - 1)
1997                                 len = maxlen - 1;
1998
1999                         if (*ppos > len)
2000                                 return 0;
2001                         len = *ppos;
2002                 } else {
2003                         /* Start writing from beginning of buffer. */
2004                         len = 0;
2005                 }
2006
2007                 *ppos += *lenp;
2008                 p = buffer;
2009                 while ((p - buffer) < *lenp && len < maxlen - 1) {
2010                         if (get_user(c, p++))
2011                                 return -EFAULT;
2012                         if (c == 0 || c == '\n')
2013                                 break;
2014                         data[len++] = c;
2015                 }
2016                 data[len] = 0;
2017         } else {
2018                 len = strlen(data);
2019                 if (len > maxlen)
2020                         len = maxlen;
2021
2022                 if (*ppos > len) {
2023                         *lenp = 0;
2024                         return 0;
2025                 }
2026
2027                 data += *ppos;
2028                 len  -= *ppos;
2029
2030                 if (len > *lenp)
2031                         len = *lenp;
2032                 if (len)
2033                         if (copy_to_user(buffer, data, len))
2034                                 return -EFAULT;
2035                 if (len < *lenp) {
2036                         if (put_user('\n', buffer + len))
2037                                 return -EFAULT;
2038                         len++;
2039                 }
2040                 *lenp = len;
2041                 *ppos += len;
2042         }
2043         return 0;
2044 }
2045
2046 static void warn_sysctl_write(struct ctl_table *table)
2047 {
2048         pr_warn_once("%s wrote to %s when file position was not 0!\n"
2049                 "This will not be supported in the future. To silence this\n"
2050                 "warning, set kernel.sysctl_writes_strict = -1\n",
2051                 current->comm, table->procname);
2052 }
2053
2054 /**
2055  * proc_first_pos_non_zero_ignore - check if first position is allowed
2056  * @ppos: file position
2057  * @table: the sysctl table
2058  *
2059  * Returns true if the first position is non-zero and the sysctl_writes_strict
2060  * mode indicates this is not allowed for numeric input types. String proc
2061  * handlers can ignore the return value.
2062  */
2063 static bool proc_first_pos_non_zero_ignore(loff_t *ppos,
2064                                            struct ctl_table *table)
2065 {
2066         if (!*ppos)
2067                 return false;
2068
2069         switch (sysctl_writes_strict) {
2070         case SYSCTL_WRITES_STRICT:
2071                 return true;
2072         case SYSCTL_WRITES_WARN:
2073                 warn_sysctl_write(table);
2074                 return false;
2075         default:
2076                 return false;
2077         }
2078 }
2079
2080 /**
2081  * proc_dostring - read a string sysctl
2082  * @table: the sysctl table
2083  * @write: %TRUE if this is a write to the sysctl file
2084  * @buffer: the user buffer
2085  * @lenp: the size of the user buffer
2086  * @ppos: file position
2087  *
2088  * Reads/writes a string from/to the user buffer. If the kernel
2089  * buffer provided is not large enough to hold the string, the
2090  * string is truncated. The copied string is %NULL-terminated.
2091  * If the string is being read by the user process, it is copied
2092  * and a newline '\n' is added. It is truncated if the buffer is
2093  * not large enough.
2094  *
2095  * Returns 0 on success.
2096  */
2097 int proc_dostring(struct ctl_table *table, int write,
2098                   void __user *buffer, size_t *lenp, loff_t *ppos)
2099 {
2100         if (write)
2101                 proc_first_pos_non_zero_ignore(ppos, table);
2102
2103         return _proc_do_string((char *)(table->data), table->maxlen, write,
2104                                (char __user *)buffer, lenp, ppos);
2105 }
2106
2107 static size_t proc_skip_spaces(char **buf)
2108 {
2109         size_t ret;
2110         char *tmp = skip_spaces(*buf);
2111         ret = tmp - *buf;
2112         *buf = tmp;
2113         return ret;
2114 }
2115
2116 static void proc_skip_char(char **buf, size_t *size, const char v)
2117 {
2118         while (*size) {
2119                 if (**buf != v)
2120                         break;
2121                 (*size)--;
2122                 (*buf)++;
2123         }
2124 }
2125
2126 /**
2127  * strtoul_lenient - parse an ASCII formatted integer from a buffer and only
2128  *                   fail on overflow
2129  *
2130  * @cp: kernel buffer containing the string to parse
2131  * @endp: pointer to store the trailing characters
2132  * @base: the base to use
2133  * @res: where the parsed integer will be stored
2134  *
2135  * In case of success 0 is returned and @res will contain the parsed integer,
2136  * @endp will hold any trailing characters.
2137  * This function will fail the parse on overflow. If there wasn't an overflow
2138  * the function will defer the decision what characters count as invalid to the
2139  * caller.
2140  */
2141 static int strtoul_lenient(const char *cp, char **endp, unsigned int base,
2142                            unsigned long *res)
2143 {
2144         unsigned long long result;
2145         unsigned int rv;
2146
2147         cp = _parse_integer_fixup_radix(cp, &base);
2148         rv = _parse_integer(cp, base, &result);
2149         if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result))
2150                 return -ERANGE;
2151
2152         cp += rv;
2153
2154         if (endp)
2155                 *endp = (char *)cp;
2156
2157         *res = (unsigned long)result;
2158         return 0;
2159 }
2160
2161 #define TMPBUFLEN 22
2162 /**
2163  * proc_get_long - reads an ASCII formatted integer from a user buffer
2164  *
2165  * @buf: a kernel buffer
2166  * @size: size of the kernel buffer
2167  * @val: this is where the number will be stored
2168  * @neg: set to %TRUE if number is negative
2169  * @perm_tr: a vector which contains the allowed trailers
2170  * @perm_tr_len: size of the perm_tr vector
2171  * @tr: pointer to store the trailer character
2172  *
2173  * In case of success %0 is returned and @buf and @size are updated with
2174  * the amount of bytes read. If @tr is non-NULL and a trailing
2175  * character exists (size is non-zero after returning from this
2176  * function), @tr is updated with the trailing character.
2177  */
2178 static int proc_get_long(char **buf, size_t *size,
2179                           unsigned long *val, bool *neg,
2180                           const char *perm_tr, unsigned perm_tr_len, char *tr)
2181 {
2182         int len;
2183         char *p, tmp[TMPBUFLEN];
2184
2185         if (!*size)
2186                 return -EINVAL;
2187
2188         len = *size;
2189         if (len > TMPBUFLEN - 1)
2190                 len = TMPBUFLEN - 1;
2191
2192         memcpy(tmp, *buf, len);
2193
2194         tmp[len] = 0;
2195         p = tmp;
2196         if (*p == '-' && *size > 1) {
2197                 *neg = true;
2198                 p++;
2199         } else
2200                 *neg = false;
2201         if (!isdigit(*p))
2202                 return -EINVAL;
2203
2204         if (strtoul_lenient(p, &p, 0, val))
2205                 return -EINVAL;
2206
2207         len = p - tmp;
2208
2209         /* We don't know if the next char is whitespace thus we may accept
2210          * invalid integers (e.g. 1234...a) or two integers instead of one
2211          * (e.g. 123...1). So lets not allow such large numbers. */
2212         if (len == TMPBUFLEN - 1)
2213                 return -EINVAL;
2214
2215         if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len))
2216                 return -EINVAL;
2217
2218         if (tr && (len < *size))
2219                 *tr = *p;
2220
2221         *buf += len;
2222         *size -= len;
2223
2224         return 0;
2225 }
2226
2227 /**
2228  * proc_put_long - converts an integer to a decimal ASCII formatted string
2229  *
2230  * @buf: the user buffer
2231  * @size: the size of the user buffer
2232  * @val: the integer to be converted
2233  * @neg: sign of the number, %TRUE for negative
2234  *
2235  * In case of success %0 is returned and @buf and @size are updated with
2236  * the amount of bytes written.
2237  */
2238 static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
2239                           bool neg)
2240 {
2241         int len;
2242         char tmp[TMPBUFLEN], *p = tmp;
2243
2244         sprintf(p, "%s%lu", neg ? "-" : "", val);
2245         len = strlen(tmp);
2246         if (len > *size)
2247                 len = *size;
2248         if (copy_to_user(*buf, tmp, len))
2249                 return -EFAULT;
2250         *size -= len;
2251         *buf += len;
2252         return 0;
2253 }
2254 #undef TMPBUFLEN
2255
2256 static int proc_put_char(void __user **buf, size_t *size, char c)
2257 {
2258         if (*size) {
2259                 char __user **buffer = (char __user **)buf;
2260                 if (put_user(c, *buffer))
2261                         return -EFAULT;
2262                 (*size)--, (*buffer)++;
2263                 *buf = *buffer;
2264         }
2265         return 0;
2266 }
2267
2268 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp,
2269                                  int *valp,
2270                                  int write, void *data)
2271 {
2272         if (write) {
2273                 if (*negp) {
2274                         if (*lvalp > (unsigned long) INT_MAX + 1)
2275                                 return -EINVAL;
2276                         *valp = -*lvalp;
2277                 } else {
2278                         if (*lvalp > (unsigned long) INT_MAX)
2279                                 return -EINVAL;
2280                         *valp = *lvalp;
2281                 }
2282         } else {
2283                 int val = *valp;
2284                 if (val < 0) {
2285                         *negp = true;
2286                         *lvalp = -(unsigned long)val;
2287                 } else {
2288                         *negp = false;
2289                         *lvalp = (unsigned long)val;
2290                 }
2291         }
2292         return 0;
2293 }
2294
2295 static int do_proc_douintvec_conv(unsigned long *lvalp,
2296                                   unsigned int *valp,
2297                                   int write, void *data)
2298 {
2299         if (write) {
2300                 if (*lvalp > UINT_MAX)
2301                         return -EINVAL;
2302                 *valp = *lvalp;
2303         } else {
2304                 unsigned int val = *valp;
2305                 *lvalp = (unsigned long)val;
2306         }
2307         return 0;
2308 }
2309
2310 static const char proc_wspace_sep[] = { ' ', '\t', '\n' };
2311
2312 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table,
2313                   int write, void __user *buffer,
2314                   size_t *lenp, loff_t *ppos,
2315                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2316                               int write, void *data),
2317                   void *data)
2318 {
2319         int *i, vleft, first = 1, err = 0;
2320         size_t left;
2321         char *kbuf = NULL, *p;
2322         
2323         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2324                 *lenp = 0;
2325                 return 0;
2326         }
2327         
2328         i = (int *) tbl_data;
2329         vleft = table->maxlen / sizeof(*i);
2330         left = *lenp;
2331
2332         if (!conv)
2333                 conv = do_proc_dointvec_conv;
2334
2335         if (write) {
2336                 if (proc_first_pos_non_zero_ignore(ppos, table))
2337                         goto out;
2338
2339                 if (left > PAGE_SIZE - 1)
2340                         left = PAGE_SIZE - 1;
2341                 p = kbuf = memdup_user_nul(buffer, left);
2342                 if (IS_ERR(kbuf))
2343                         return PTR_ERR(kbuf);
2344         }
2345
2346         for (; left && vleft--; i++, first=0) {
2347                 unsigned long lval;
2348                 bool neg;
2349
2350                 if (write) {
2351                         left -= proc_skip_spaces(&p);
2352
2353                         if (!left)
2354                                 break;
2355                         err = proc_get_long(&p, &left, &lval, &neg,
2356                                              proc_wspace_sep,
2357                                              sizeof(proc_wspace_sep), NULL);
2358                         if (err)
2359                                 break;
2360                         if (conv(&neg, &lval, i, 1, data)) {
2361                                 err = -EINVAL;
2362                                 break;
2363                         }
2364                 } else {
2365                         if (conv(&neg, &lval, i, 0, data)) {
2366                                 err = -EINVAL;
2367                                 break;
2368                         }
2369                         if (!first)
2370                                 err = proc_put_char(&buffer, &left, '\t');
2371                         if (err)
2372                                 break;
2373                         err = proc_put_long(&buffer, &left, lval, neg);
2374                         if (err)
2375                                 break;
2376                 }
2377         }
2378
2379         if (!write && !first && left && !err)
2380                 err = proc_put_char(&buffer, &left, '\n');
2381         if (write && !err && left)
2382                 left -= proc_skip_spaces(&p);
2383         if (write) {
2384                 kfree(kbuf);
2385                 if (first)
2386                         return err ? : -EINVAL;
2387         }
2388         *lenp -= left;
2389 out:
2390         *ppos += *lenp;
2391         return err;
2392 }
2393
2394 static int do_proc_dointvec(struct ctl_table *table, int write,
2395                   void __user *buffer, size_t *lenp, loff_t *ppos,
2396                   int (*conv)(bool *negp, unsigned long *lvalp, int *valp,
2397                               int write, void *data),
2398                   void *data)
2399 {
2400         return __do_proc_dointvec(table->data, table, write,
2401                         buffer, lenp, ppos, conv, data);
2402 }
2403
2404 static int do_proc_douintvec_w(unsigned int *tbl_data,
2405                                struct ctl_table *table,
2406                                void __user *buffer,
2407                                size_t *lenp, loff_t *ppos,
2408                                int (*conv)(unsigned long *lvalp,
2409                                            unsigned int *valp,
2410                                            int write, void *data),
2411                                void *data)
2412 {
2413         unsigned long lval;
2414         int err = 0;
2415         size_t left;
2416         bool neg;
2417         char *kbuf = NULL, *p;
2418
2419         left = *lenp;
2420
2421         if (proc_first_pos_non_zero_ignore(ppos, table))
2422                 goto bail_early;
2423
2424         if (left > PAGE_SIZE - 1)
2425                 left = PAGE_SIZE - 1;
2426
2427         p = kbuf = memdup_user_nul(buffer, left);
2428         if (IS_ERR(kbuf))
2429                 return -EINVAL;
2430
2431         left -= proc_skip_spaces(&p);
2432         if (!left) {
2433                 err = -EINVAL;
2434                 goto out_free;
2435         }
2436
2437         err = proc_get_long(&p, &left, &lval, &neg,
2438                              proc_wspace_sep,
2439                              sizeof(proc_wspace_sep), NULL);
2440         if (err || neg) {
2441                 err = -EINVAL;
2442                 goto out_free;
2443         }
2444
2445         if (conv(&lval, tbl_data, 1, data)) {
2446                 err = -EINVAL;
2447                 goto out_free;
2448         }
2449
2450         if (!err && left)
2451                 left -= proc_skip_spaces(&p);
2452
2453 out_free:
2454         kfree(kbuf);
2455         if (err)
2456                 return -EINVAL;
2457
2458         return 0;
2459
2460         /* This is in keeping with old __do_proc_dointvec() */
2461 bail_early:
2462         *ppos += *lenp;
2463         return err;
2464 }
2465
2466 static int do_proc_douintvec_r(unsigned int *tbl_data, void __user *buffer,
2467                                size_t *lenp, loff_t *ppos,
2468                                int (*conv)(unsigned long *lvalp,
2469                                            unsigned int *valp,
2470                                            int write, void *data),
2471                                void *data)
2472 {
2473         unsigned long lval;
2474         int err = 0;
2475         size_t left;
2476
2477         left = *lenp;
2478
2479         if (conv(&lval, tbl_data, 0, data)) {
2480                 err = -EINVAL;
2481                 goto out;
2482         }
2483
2484         err = proc_put_long(&buffer, &left, lval, false);
2485         if (err || !left)
2486                 goto out;
2487
2488         err = proc_put_char(&buffer, &left, '\n');
2489
2490 out:
2491         *lenp -= left;
2492         *ppos += *lenp;
2493
2494         return err;
2495 }
2496
2497 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table,
2498                                int write, void __user *buffer,
2499                                size_t *lenp, loff_t *ppos,
2500                                int (*conv)(unsigned long *lvalp,
2501                                            unsigned int *valp,
2502                                            int write, void *data),
2503                                void *data)
2504 {
2505         unsigned int *i, vleft;
2506
2507         if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) {
2508                 *lenp = 0;
2509                 return 0;
2510         }
2511
2512         i = (unsigned int *) tbl_data;
2513         vleft = table->maxlen / sizeof(*i);
2514
2515         /*
2516          * Arrays are not supported, keep this simple. *Do not* add
2517          * support for them.
2518          */
2519         if (vleft != 1) {
2520                 *lenp = 0;
2521                 return -EINVAL;
2522         }
2523
2524         if (!conv)
2525                 conv = do_proc_douintvec_conv;
2526
2527         if (write)
2528                 return do_proc_douintvec_w(i, table, buffer, lenp, ppos,
2529                                            conv, data);
2530         return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data);
2531 }
2532
2533 static int do_proc_douintvec(struct ctl_table *table, int write,
2534                              void __user *buffer, size_t *lenp, loff_t *ppos,
2535                              int (*conv)(unsigned long *lvalp,
2536                                          unsigned int *valp,
2537                                          int write, void *data),
2538                              void *data)
2539 {
2540         return __do_proc_douintvec(table->data, table, write,
2541                                    buffer, lenp, ppos, conv, data);
2542 }
2543
2544 /**
2545  * proc_dointvec - read a vector of integers
2546  * @table: the sysctl table
2547  * @write: %TRUE if this is a write to the sysctl file
2548  * @buffer: the user buffer
2549  * @lenp: the size of the user buffer
2550  * @ppos: file position
2551  *
2552  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2553  * values from/to the user buffer, treated as an ASCII string. 
2554  *
2555  * Returns 0 on success.
2556  */
2557 int proc_dointvec(struct ctl_table *table, int write,
2558                      void __user *buffer, size_t *lenp, loff_t *ppos)
2559 {
2560         return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL);
2561 }
2562
2563 #ifdef CONFIG_COMPACTION
2564 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table,
2565                                                int write, void __user *buffer,
2566                                                size_t *lenp, loff_t *ppos)
2567 {
2568         int ret, old;
2569
2570         if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write)
2571                 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2572
2573         old = *(int *)table->data;
2574         ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2575         if (ret)
2576                 return ret;
2577         if (old != *(int *)table->data)
2578                 pr_warn_once("sysctl attribute %s changed by %s[%d]\n",
2579                              table->procname, current->comm,
2580                              task_pid_nr(current));
2581         return ret;
2582 }
2583 #endif
2584
2585 /**
2586  * proc_douintvec - read a vector of unsigned integers
2587  * @table: the sysctl table
2588  * @write: %TRUE if this is a write to the sysctl file
2589  * @buffer: the user buffer
2590  * @lenp: the size of the user buffer
2591  * @ppos: file position
2592  *
2593  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2594  * values from/to the user buffer, treated as an ASCII string.
2595  *
2596  * Returns 0 on success.
2597  */
2598 int proc_douintvec(struct ctl_table *table, int write,
2599                      void __user *buffer, size_t *lenp, loff_t *ppos)
2600 {
2601         return do_proc_douintvec(table, write, buffer, lenp, ppos,
2602                                  do_proc_douintvec_conv, NULL);
2603 }
2604
2605 /*
2606  * Taint values can only be increased
2607  * This means we can safely use a temporary.
2608  */
2609 static int proc_taint(struct ctl_table *table, int write,
2610                                void __user *buffer, size_t *lenp, loff_t *ppos)
2611 {
2612         struct ctl_table t;
2613         unsigned long tmptaint = get_taint();
2614         int err;
2615
2616         if (write && !capable(CAP_SYS_ADMIN))
2617                 return -EPERM;
2618
2619         t = *table;
2620         t.data = &tmptaint;
2621         err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos);
2622         if (err < 0)
2623                 return err;
2624
2625         if (write) {
2626                 /*
2627                  * Poor man's atomic or. Not worth adding a primitive
2628                  * to everyone's atomic.h for this
2629                  */
2630                 int i;
2631                 for (i = 0; i < BITS_PER_LONG && tmptaint >> i; i++) {
2632                         if ((tmptaint >> i) & 1)
2633                                 add_taint(i, LOCKDEP_STILL_OK);
2634                 }
2635         }
2636
2637         return err;
2638 }
2639
2640 #ifdef CONFIG_PRINTK
2641 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
2642                                 void __user *buffer, size_t *lenp, loff_t *ppos)
2643 {
2644         if (write && !capable(CAP_SYS_ADMIN))
2645                 return -EPERM;
2646
2647         return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2648 }
2649 #endif
2650
2651 /**
2652  * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure
2653  * @min: pointer to minimum allowable value
2654  * @max: pointer to maximum allowable value
2655  *
2656  * The do_proc_dointvec_minmax_conv_param structure provides the
2657  * minimum and maximum values for doing range checking for those sysctl
2658  * parameters that use the proc_dointvec_minmax() handler.
2659  */
2660 struct do_proc_dointvec_minmax_conv_param {
2661         int *min;
2662         int *max;
2663 };
2664
2665 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp,
2666                                         int *valp,
2667                                         int write, void *data)
2668 {
2669         int tmp, ret;
2670         struct do_proc_dointvec_minmax_conv_param *param = data;
2671         /*
2672          * If writing, first do so via a temporary local int so we can
2673          * bounds-check it before touching *valp.
2674          */
2675         int *ip = write ? &tmp : valp;
2676
2677         ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data);
2678         if (ret)
2679                 return ret;
2680
2681         if (write) {
2682                 if ((param->min && *param->min > tmp) ||
2683                     (param->max && *param->max < tmp))
2684                         return -EINVAL;
2685                 *valp = tmp;
2686         }
2687
2688         return 0;
2689 }
2690
2691 /**
2692  * proc_dointvec_minmax - read a vector of integers with min/max values
2693  * @table: the sysctl table
2694  * @write: %TRUE if this is a write to the sysctl file
2695  * @buffer: the user buffer
2696  * @lenp: the size of the user buffer
2697  * @ppos: file position
2698  *
2699  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
2700  * values from/to the user buffer, treated as an ASCII string.
2701  *
2702  * This routine will ensure the values are within the range specified by
2703  * table->extra1 (min) and table->extra2 (max).
2704  *
2705  * Returns 0 on success or -EINVAL on write when the range check fails.
2706  */
2707 int proc_dointvec_minmax(struct ctl_table *table, int write,
2708                   void __user *buffer, size_t *lenp, loff_t *ppos)
2709 {
2710         struct do_proc_dointvec_minmax_conv_param param = {
2711                 .min = (int *) table->extra1,
2712                 .max = (int *) table->extra2,
2713         };
2714         return do_proc_dointvec(table, write, buffer, lenp, ppos,
2715                                 do_proc_dointvec_minmax_conv, &param);
2716 }
2717
2718 /**
2719  * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure
2720  * @min: pointer to minimum allowable value
2721  * @max: pointer to maximum allowable value
2722  *
2723  * The do_proc_douintvec_minmax_conv_param structure provides the
2724  * minimum and maximum values for doing range checking for those sysctl
2725  * parameters that use the proc_douintvec_minmax() handler.
2726  */
2727 struct do_proc_douintvec_minmax_conv_param {
2728         unsigned int *min;
2729         unsigned int *max;
2730 };
2731
2732 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp,
2733                                          unsigned int *valp,
2734                                          int write, void *data)
2735 {
2736         int ret;
2737         unsigned int tmp;
2738         struct do_proc_douintvec_minmax_conv_param *param = data;
2739         /* write via temporary local uint for bounds-checking */
2740         unsigned int *up = write ? &tmp : valp;
2741
2742         ret = do_proc_douintvec_conv(lvalp, up, write, data);
2743         if (ret)
2744                 return ret;
2745
2746         if (write) {
2747                 if ((param->min && *param->min > tmp) ||
2748                     (param->max && *param->max < tmp))
2749                         return -ERANGE;
2750
2751                 *valp = tmp;
2752         }
2753
2754         return 0;
2755 }
2756
2757 /**
2758  * proc_douintvec_minmax - read a vector of unsigned ints with min/max values
2759  * @table: the sysctl table
2760  * @write: %TRUE if this is a write to the sysctl file
2761  * @buffer: the user buffer
2762  * @lenp: the size of the user buffer
2763  * @ppos: file position
2764  *
2765  * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer
2766  * values from/to the user buffer, treated as an ASCII string. Negative
2767  * strings are not allowed.
2768  *
2769  * This routine will ensure the values are within the range specified by
2770  * table->extra1 (min) and table->extra2 (max). There is a final sanity
2771  * check for UINT_MAX to avoid having to support wrap around uses from
2772  * userspace.
2773  *
2774  * Returns 0 on success or -ERANGE on write when the range check fails.
2775  */
2776 int proc_douintvec_minmax(struct ctl_table *table, int write,
2777                           void __user *buffer, size_t *lenp, loff_t *ppos)
2778 {
2779         struct do_proc_douintvec_minmax_conv_param param = {
2780                 .min = (unsigned int *) table->extra1,
2781                 .max = (unsigned int *) table->extra2,
2782         };
2783         return do_proc_douintvec(table, write, buffer, lenp, ppos,
2784                                  do_proc_douintvec_minmax_conv, &param);
2785 }
2786
2787 static int do_proc_dopipe_max_size_conv(unsigned long *lvalp,
2788                                         unsigned int *valp,
2789                                         int write, void *data)
2790 {
2791         if (write) {
2792                 unsigned int val;
2793
2794                 val = round_pipe_size(*lvalp);
2795                 if (val == 0)
2796                         return -EINVAL;
2797
2798                 *valp = val;
2799         } else {
2800                 unsigned int val = *valp;
2801                 *lvalp = (unsigned long) val;
2802         }
2803
2804         return 0;
2805 }
2806
2807 static int proc_dopipe_max_size(struct ctl_table *table, int write,
2808                                 void __user *buffer, size_t *lenp, loff_t *ppos)
2809 {
2810         return do_proc_douintvec(table, write, buffer, lenp, ppos,
2811                                  do_proc_dopipe_max_size_conv, NULL);
2812 }
2813
2814 static void validate_coredump_safety(void)
2815 {
2816 #ifdef CONFIG_COREDUMP
2817         if (suid_dumpable == SUID_DUMP_ROOT &&
2818             core_pattern[0] != '/' && core_pattern[0] != '|') {
2819                 printk(KERN_WARNING
2820 "Unsafe core_pattern used with fs.suid_dumpable=2.\n"
2821 "Pipe handler or fully qualified core dump path required.\n"
2822 "Set kernel.core_pattern before fs.suid_dumpable.\n"
2823                 );
2824         }
2825 #endif
2826 }
2827
2828 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
2829                 void __user *buffer, size_t *lenp, loff_t *ppos)
2830 {
2831         int error = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
2832         if (!error)
2833                 validate_coredump_safety();
2834         return error;
2835 }
2836
2837 #ifdef CONFIG_COREDUMP
2838 static int proc_dostring_coredump(struct ctl_table *table, int write,
2839                   void __user *buffer, size_t *lenp, loff_t *ppos)
2840 {
2841         int error = proc_dostring(table, write, buffer, lenp, ppos);
2842         if (!error)
2843                 validate_coredump_safety();
2844         return error;
2845 }
2846 #endif
2847
2848 #ifdef CONFIG_MAGIC_SYSRQ
2849 static int sysrq_sysctl_handler(struct ctl_table *table, int write,
2850                                 void __user *buffer, size_t *lenp, loff_t *ppos)
2851 {
2852         int tmp, ret;
2853
2854         tmp = sysrq_mask();
2855
2856         ret = __do_proc_dointvec(&tmp, table, write, buffer,
2857                                lenp, ppos, NULL, NULL);
2858         if (ret || !write)
2859                 return ret;
2860
2861         if (write)
2862                 sysrq_toggle_support(tmp);
2863
2864         return 0;
2865 }
2866 #endif
2867
2868 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, int write,
2869                                      void __user *buffer,
2870                                      size_t *lenp, loff_t *ppos,
2871                                      unsigned long convmul,
2872                                      unsigned long convdiv)
2873 {
2874         unsigned long *i, *min, *max;
2875         int vleft, first = 1, err = 0;
2876         size_t left;
2877         char *kbuf = NULL, *p;
2878
2879         if (!data || !table->maxlen || !*lenp || (*ppos && !write)) {
2880                 *lenp = 0;
2881                 return 0;
2882         }
2883
2884         i = (unsigned long *) data;
2885         min = (unsigned long *) table->extra1;
2886         max = (unsigned long *) table->extra2;
2887         vleft = table->maxlen / sizeof(unsigned long);
2888         left = *lenp;
2889
2890         if (write) {
2891                 if (proc_first_pos_non_zero_ignore(ppos, table))
2892                         goto out;
2893
2894                 if (left > PAGE_SIZE - 1)
2895                         left = PAGE_SIZE - 1;
2896                 p = kbuf = memdup_user_nul(buffer, left);
2897                 if (IS_ERR(kbuf))
2898                         return PTR_ERR(kbuf);
2899         }
2900
2901         for (; left && vleft--; i++, first = 0) {
2902                 unsigned long val;
2903
2904                 if (write) {
2905                         bool neg;
2906
2907                         left -= proc_skip_spaces(&p);
2908                         if (!left)
2909                                 break;
2910
2911                         err = proc_get_long(&p, &left, &val, &neg,
2912                                              proc_wspace_sep,
2913                                              sizeof(proc_wspace_sep), NULL);
2914                         if (err)
2915                                 break;
2916                         if (neg)
2917                                 continue;
2918                         val = convmul * val / convdiv;
2919                         if ((min && val < *min) || (max && val > *max)) {
2920                                 err = -EINVAL;
2921                                 break;
2922                         }
2923                         *i = val;
2924                 } else {
2925                         val = convdiv * (*i) / convmul;
2926                         if (!first) {
2927                                 err = proc_put_char(&buffer, &left, '\t');
2928                                 if (err)
2929                                         break;
2930                         }
2931                         err = proc_put_long(&buffer, &left, val, false);
2932                         if (err)
2933                                 break;
2934                 }
2935         }
2936
2937         if (!write && !first && left && !err)
2938                 err = proc_put_char(&buffer, &left, '\n');
2939         if (write && !err)
2940                 left -= proc_skip_spaces(&p);
2941         if (write) {
2942                 kfree(kbuf);
2943                 if (first)
2944                         return err ? : -EINVAL;
2945         }
2946         *lenp -= left;
2947 out:
2948         *ppos += *lenp;
2949         return err;
2950 }
2951
2952 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write,
2953                                      void __user *buffer,
2954                                      size_t *lenp, loff_t *ppos,
2955                                      unsigned long convmul,
2956                                      unsigned long convdiv)
2957 {
2958         return __do_proc_doulongvec_minmax(table->data, table, write,
2959                         buffer, lenp, ppos, convmul, convdiv);
2960 }
2961
2962 /**
2963  * proc_doulongvec_minmax - read a vector of long integers with min/max values
2964  * @table: the sysctl table
2965  * @write: %TRUE if this is a write to the sysctl file
2966  * @buffer: the user buffer
2967  * @lenp: the size of the user buffer
2968  * @ppos: file position
2969  *
2970  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2971  * values from/to the user buffer, treated as an ASCII string.
2972  *
2973  * This routine will ensure the values are within the range specified by
2974  * table->extra1 (min) and table->extra2 (max).
2975  *
2976  * Returns 0 on success.
2977  */
2978 int proc_doulongvec_minmax(struct ctl_table *table, int write,
2979                            void __user *buffer, size_t *lenp, loff_t *ppos)
2980 {
2981     return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l);
2982 }
2983
2984 /**
2985  * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values
2986  * @table: the sysctl table
2987  * @write: %TRUE if this is a write to the sysctl file
2988  * @buffer: the user buffer
2989  * @lenp: the size of the user buffer
2990  * @ppos: file position
2991  *
2992  * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long
2993  * values from/to the user buffer, treated as an ASCII string. The values
2994  * are treated as milliseconds, and converted to jiffies when they are stored.
2995  *
2996  * This routine will ensure the values are within the range specified by
2997  * table->extra1 (min) and table->extra2 (max).
2998  *
2999  * Returns 0 on success.
3000  */
3001 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3002                                       void __user *buffer,
3003                                       size_t *lenp, loff_t *ppos)
3004 {
3005     return do_proc_doulongvec_minmax(table, write, buffer,
3006                                      lenp, ppos, HZ, 1000l);
3007 }
3008
3009
3010 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp,
3011                                          int *valp,
3012                                          int write, void *data)
3013 {
3014         if (write) {
3015                 if (*lvalp > INT_MAX / HZ)
3016                         return 1;
3017                 *valp = *negp ? -(*lvalp*HZ) : (*lvalp*HZ);
3018         } else {
3019                 int val = *valp;
3020                 unsigned long lval;
3021                 if (val < 0) {
3022                         *negp = true;
3023                         lval = -(unsigned long)val;
3024                 } else {
3025                         *negp = false;
3026                         lval = (unsigned long)val;
3027                 }
3028                 *lvalp = lval / HZ;
3029         }
3030         return 0;
3031 }
3032
3033 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp,
3034                                                 int *valp,
3035                                                 int write, void *data)
3036 {
3037         if (write) {
3038                 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ)
3039                         return 1;
3040                 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp);
3041         } else {
3042                 int val = *valp;
3043                 unsigned long lval;
3044                 if (val < 0) {
3045                         *negp = true;
3046                         lval = -(unsigned long)val;
3047                 } else {
3048                         *negp = false;
3049                         lval = (unsigned long)val;
3050                 }
3051                 *lvalp = jiffies_to_clock_t(lval);
3052         }
3053         return 0;
3054 }
3055
3056 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp,
3057                                             int *valp,
3058                                             int write, void *data)
3059 {
3060         if (write) {
3061                 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp);
3062
3063                 if (jif > INT_MAX)
3064                         return 1;
3065                 *valp = (int)jif;
3066         } else {
3067                 int val = *valp;
3068                 unsigned long lval;
3069                 if (val < 0) {
3070                         *negp = true;
3071                         lval = -(unsigned long)val;
3072                 } else {
3073                         *negp = false;
3074                         lval = (unsigned long)val;
3075                 }
3076                 *lvalp = jiffies_to_msecs(lval);
3077         }
3078         return 0;
3079 }
3080
3081 /**
3082  * proc_dointvec_jiffies - read a vector of integers as seconds
3083  * @table: the sysctl table
3084  * @write: %TRUE if this is a write to the sysctl file
3085  * @buffer: the user buffer
3086  * @lenp: the size of the user buffer
3087  * @ppos: file position
3088  *
3089  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3090  * values from/to the user buffer, treated as an ASCII string. 
3091  * The values read are assumed to be in seconds, and are converted into
3092  * jiffies.
3093  *
3094  * Returns 0 on success.
3095  */
3096 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3097                           void __user *buffer, size_t *lenp, loff_t *ppos)
3098 {
3099     return do_proc_dointvec(table,write,buffer,lenp,ppos,
3100                             do_proc_dointvec_jiffies_conv,NULL);
3101 }
3102
3103 /**
3104  * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds
3105  * @table: the sysctl table
3106  * @write: %TRUE if this is a write to the sysctl file
3107  * @buffer: the user buffer
3108  * @lenp: the size of the user buffer
3109  * @ppos: pointer to the file position
3110  *
3111  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3112  * values from/to the user buffer, treated as an ASCII string. 
3113  * The values read are assumed to be in 1/USER_HZ seconds, and 
3114  * are converted into jiffies.
3115  *
3116  * Returns 0 on success.
3117  */
3118 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3119                                  void __user *buffer, size_t *lenp, loff_t *ppos)
3120 {
3121     return do_proc_dointvec(table,write,buffer,lenp,ppos,
3122                             do_proc_dointvec_userhz_jiffies_conv,NULL);
3123 }
3124
3125 /**
3126  * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds
3127  * @table: the sysctl table
3128  * @write: %TRUE if this is a write to the sysctl file
3129  * @buffer: the user buffer
3130  * @lenp: the size of the user buffer
3131  * @ppos: file position
3132  * @ppos: the current position in the file
3133  *
3134  * Reads/writes up to table->maxlen/sizeof(unsigned int) integer
3135  * values from/to the user buffer, treated as an ASCII string. 
3136  * The values read are assumed to be in 1/1000 seconds, and 
3137  * are converted into jiffies.
3138  *
3139  * Returns 0 on success.
3140  */
3141 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3142                              void __user *buffer, size_t *lenp, loff_t *ppos)
3143 {
3144         return do_proc_dointvec(table, write, buffer, lenp, ppos,
3145                                 do_proc_dointvec_ms_jiffies_conv, NULL);
3146 }
3147
3148 static int proc_do_cad_pid(struct ctl_table *table, int write,
3149                            void __user *buffer, size_t *lenp, loff_t *ppos)
3150 {
3151         struct pid *new_pid;
3152         pid_t tmp;
3153         int r;
3154
3155         tmp = pid_vnr(cad_pid);
3156
3157         r = __do_proc_dointvec(&tmp, table, write, buffer,
3158                                lenp, ppos, NULL, NULL);
3159         if (r || !write)
3160                 return r;
3161
3162         new_pid = find_get_pid(tmp);
3163         if (!new_pid)
3164                 return -ESRCH;
3165
3166         put_pid(xchg(&cad_pid, new_pid));
3167         return 0;
3168 }
3169
3170 /**
3171  * proc_do_large_bitmap - read/write from/to a large bitmap
3172  * @table: the sysctl table
3173  * @write: %TRUE if this is a write to the sysctl file
3174  * @buffer: the user buffer
3175  * @lenp: the size of the user buffer
3176  * @ppos: file position
3177  *
3178  * The bitmap is stored at table->data and the bitmap length (in bits)
3179  * in table->maxlen.
3180  *
3181  * We use a range comma separated format (e.g. 1,3-4,10-10) so that
3182  * large bitmaps may be represented in a compact manner. Writing into
3183  * the file will clear the bitmap then update it with the given input.
3184  *
3185  * Returns 0 on success.
3186  */
3187 int proc_do_large_bitmap(struct ctl_table *table, int write,
3188                          void __user *buffer, size_t *lenp, loff_t *ppos)
3189 {
3190         int err = 0;
3191         bool first = 1;
3192         size_t left = *lenp;
3193         unsigned long bitmap_len = table->maxlen;
3194         unsigned long *bitmap = *(unsigned long **) table->data;
3195         unsigned long *tmp_bitmap = NULL;
3196         char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c;
3197
3198         if (!bitmap || !bitmap_len || !left || (*ppos && !write)) {
3199                 *lenp = 0;
3200                 return 0;
3201         }
3202
3203         if (write) {
3204                 char *kbuf, *p;
3205                 size_t skipped = 0;
3206
3207                 if (left > PAGE_SIZE - 1) {
3208                         left = PAGE_SIZE - 1;
3209                         /* How much of the buffer we'll skip this pass */
3210                         skipped = *lenp - left;
3211                 }
3212
3213                 p = kbuf = memdup_user_nul(buffer, left);
3214                 if (IS_ERR(kbuf))
3215                         return PTR_ERR(kbuf);
3216
3217                 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL);
3218                 if (!tmp_bitmap) {
3219                         kfree(kbuf);
3220                         return -ENOMEM;
3221                 }
3222                 proc_skip_char(&p, &left, '\n');
3223                 while (!err && left) {
3224                         unsigned long val_a, val_b;
3225                         bool neg;
3226                         size_t saved_left;
3227
3228                         /* In case we stop parsing mid-number, we can reset */
3229                         saved_left = left;
3230                         err = proc_get_long(&p, &left, &val_a, &neg, tr_a,
3231                                              sizeof(tr_a), &c);
3232                         /*
3233                          * If we consumed the entirety of a truncated buffer or
3234                          * only one char is left (may be a "-"), then stop here,
3235                          * reset, & come back for more.
3236                          */
3237                         if ((left <= 1) && skipped) {
3238                                 left = saved_left;
3239                                 break;
3240                         }
3241
3242                         if (err)
3243                                 break;
3244                         if (val_a >= bitmap_len || neg) {
3245                                 err = -EINVAL;
3246                                 break;
3247                         }
3248
3249                         val_b = val_a;
3250                         if (left) {
3251                                 p++;
3252                                 left--;
3253                         }
3254
3255                         if (c == '-') {
3256                                 err = proc_get_long(&p, &left, &val_b,
3257                                                      &neg, tr_b, sizeof(tr_b),
3258                                                      &c);
3259                                 /*
3260                                  * If we consumed all of a truncated buffer or
3261                                  * then stop here, reset, & come back for more.
3262                                  */
3263                                 if (!left && skipped) {
3264                                         left = saved_left;
3265                                         break;
3266                                 }
3267
3268                                 if (err)
3269                                         break;
3270                                 if (val_b >= bitmap_len || neg ||
3271                                     val_a > val_b) {
3272                                         err = -EINVAL;
3273                                         break;
3274                                 }
3275                                 if (left) {
3276                                         p++;
3277                                         left--;
3278                                 }
3279                         }
3280
3281                         bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1);
3282                         first = 0;
3283                         proc_skip_char(&p, &left, '\n');
3284                 }
3285                 kfree(kbuf);
3286                 left += skipped;
3287         } else {
3288                 unsigned long bit_a, bit_b = 0;
3289
3290                 while (left) {
3291                         bit_a = find_next_bit(bitmap, bitmap_len, bit_b);
3292                         if (bit_a >= bitmap_len)
3293                                 break;
3294                         bit_b = find_next_zero_bit(bitmap, bitmap_len,
3295                                                    bit_a + 1) - 1;
3296
3297                         if (!first) {
3298                                 err = proc_put_char(&buffer, &left, ',');
3299                                 if (err)
3300                                         break;
3301                         }
3302                         err = proc_put_long(&buffer, &left, bit_a, false);
3303                         if (err)
3304                                 break;
3305                         if (bit_a != bit_b) {
3306                                 err = proc_put_char(&buffer, &left, '-');
3307                                 if (err)
3308                                         break;
3309                                 err = proc_put_long(&buffer, &left, bit_b, false);
3310                                 if (err)
3311                                         break;
3312                         }
3313
3314                         first = 0; bit_b++;
3315                 }
3316                 if (!err)
3317                         err = proc_put_char(&buffer, &left, '\n');
3318         }
3319
3320         if (!err) {
3321                 if (write) {
3322                         if (*ppos)
3323                                 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len);
3324                         else
3325                                 bitmap_copy(bitmap, tmp_bitmap, bitmap_len);
3326                 }
3327                 *lenp -= left;
3328                 *ppos += *lenp;
3329         }
3330
3331         bitmap_free(tmp_bitmap);
3332         return err;
3333 }
3334
3335 #else /* CONFIG_PROC_SYSCTL */
3336
3337 int proc_dostring(struct ctl_table *table, int write,
3338                   void __user *buffer, size_t *lenp, loff_t *ppos)
3339 {
3340         return -ENOSYS;
3341 }
3342
3343 int proc_dointvec(struct ctl_table *table, int write,
3344                   void __user *buffer, size_t *lenp, loff_t *ppos)
3345 {
3346         return -ENOSYS;
3347 }
3348
3349 int proc_douintvec(struct ctl_table *table, int write,
3350                   void __user *buffer, size_t *lenp, loff_t *ppos)
3351 {
3352         return -ENOSYS;
3353 }
3354
3355 int proc_dointvec_minmax(struct ctl_table *table, int write,
3356                     void __user *buffer, size_t *lenp, loff_t *ppos)
3357 {
3358         return -ENOSYS;
3359 }
3360
3361 int proc_douintvec_minmax(struct ctl_table *table, int write,
3362                           void __user *buffer, size_t *lenp, loff_t *ppos)
3363 {
3364         return -ENOSYS;
3365 }
3366
3367 int proc_dointvec_jiffies(struct ctl_table *table, int write,
3368                     void __user *buffer, size_t *lenp, loff_t *ppos)
3369 {
3370         return -ENOSYS;
3371 }
3372
3373 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write,
3374                     void __user *buffer, size_t *lenp, loff_t *ppos)
3375 {
3376         return -ENOSYS;
3377 }
3378
3379 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write,
3380                              void __user *buffer, size_t *lenp, loff_t *ppos)
3381 {
3382         return -ENOSYS;
3383 }
3384
3385 int proc_doulongvec_minmax(struct ctl_table *table, int write,
3386                     void __user *buffer, size_t *lenp, loff_t *ppos)
3387 {
3388         return -ENOSYS;
3389 }
3390
3391 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write,
3392                                       void __user *buffer,
3393                                       size_t *lenp, loff_t *ppos)
3394 {
3395     return -ENOSYS;
3396 }
3397
3398 int proc_do_large_bitmap(struct ctl_table *table, int write,
3399                          void __user *buffer, size_t *lenp, loff_t *ppos)
3400 {
3401         return -ENOSYS;
3402 }
3403
3404 #endif /* CONFIG_PROC_SYSCTL */
3405
3406 #if defined(CONFIG_SYSCTL)
3407 int proc_do_static_key(struct ctl_table *table, int write,
3408                        void __user *buffer, size_t *lenp,
3409                        loff_t *ppos)
3410 {
3411         struct static_key *key = (struct static_key *)table->data;
3412         static DEFINE_MUTEX(static_key_mutex);
3413         int val, ret;
3414         struct ctl_table tmp = {
3415                 .data   = &val,
3416                 .maxlen = sizeof(val),
3417                 .mode   = table->mode,
3418                 .extra1 = SYSCTL_ZERO,
3419                 .extra2 = SYSCTL_ONE,
3420         };
3421
3422         if (write && !capable(CAP_SYS_ADMIN))
3423                 return -EPERM;
3424
3425         mutex_lock(&static_key_mutex);
3426         val = static_key_enabled(key);
3427         ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos);
3428         if (write && !ret) {
3429                 if (val)
3430                         static_key_enable(key);
3431                 else
3432                         static_key_disable(key);
3433         }
3434         mutex_unlock(&static_key_mutex);
3435         return ret;
3436 }
3437 #endif
3438 /*
3439  * No sense putting this after each symbol definition, twice,
3440  * exception granted :-)
3441  */
3442 EXPORT_SYMBOL(proc_dointvec);
3443 EXPORT_SYMBOL(proc_douintvec);
3444 EXPORT_SYMBOL(proc_dointvec_jiffies);
3445 EXPORT_SYMBOL(proc_dointvec_minmax);
3446 EXPORT_SYMBOL_GPL(proc_douintvec_minmax);
3447 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
3448 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
3449 EXPORT_SYMBOL(proc_dostring);
3450 EXPORT_SYMBOL(proc_doulongvec_minmax);
3451 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
3452 EXPORT_SYMBOL(proc_do_large_bitmap);