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