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