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