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