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