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