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