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