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