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