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