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