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