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