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