1457c8996SThomas Gleixner // SPDX-License-Identifier: GPL-2.0-only 21da177e4SLinus Torvalds /* 31da177e4SLinus Torvalds * sysctl.c: General linux system control interface 41da177e4SLinus Torvalds * 51da177e4SLinus Torvalds * Begun 24 March 1995, Stephen Tweedie 61da177e4SLinus Torvalds * Added /proc support, Dec 1995 71da177e4SLinus Torvalds * Added bdflush entry and intvec min/max checking, 2/23/96, Tom Dyas. 81da177e4SLinus Torvalds * Added hooks for /proc/sys/net (minor, minor patch), 96/4/1, Mike Shaver. 91da177e4SLinus Torvalds * Added kernel/java-{interpreter,appletviewer}, 96/5/10, Mike Shaver. 101da177e4SLinus Torvalds * Dynamic registration fixes, Stephen Tweedie. 111da177e4SLinus Torvalds * Added kswapd-interval, ctrl-alt-del, printk stuff, 1/8/97, Chris Horn. 121da177e4SLinus Torvalds * Made sysctl support optional via CONFIG_SYSCTL, 1/10/97, Chris 131da177e4SLinus Torvalds * Horn. 141da177e4SLinus Torvalds * Added proc_doulongvec_ms_jiffies_minmax, 09/08/99, Carlos H. Bauer. 151da177e4SLinus Torvalds * Added proc_doulongvec_minmax, 09/08/99, Carlos H. Bauer. 161da177e4SLinus Torvalds * Changed linked lists to use list.h instead of lists.h, 02/24/00, Bill 171da177e4SLinus Torvalds * Wendling. 181da177e4SLinus Torvalds * The list_for_each() macro wasn't appropriate for the sysctl loop. 191da177e4SLinus Torvalds * Removed it and replaced it with older style, 03/23/00, Bill Wendling 201da177e4SLinus Torvalds */ 211da177e4SLinus Torvalds 221da177e4SLinus Torvalds #include <linux/module.h> 231da177e4SLinus Torvalds #include <linux/mm.h> 241da177e4SLinus Torvalds #include <linux/swap.h> 251da177e4SLinus Torvalds #include <linux/slab.h> 261da177e4SLinus Torvalds #include <linux/sysctl.h> 275a04cca6SAkinobu Mita #include <linux/bitmap.h> 28d33ed52dSDave Young #include <linux/signal.h> 29f39650deSAndy Shevchenko #include <linux/panic.h> 30455cd5abSDan Rosenberg #include <linux/printk.h> 311da177e4SLinus Torvalds #include <linux/proc_fs.h> 3272c2d582SAndrew Morgan #include <linux/security.h> 331da177e4SLinus Torvalds #include <linux/ctype.h> 34fd4b616bSSteven Rostedt #include <linux/kmemleak.h> 35b6459415SJakub Kicinski #include <linux/filter.h> 3662239ac2SAdrian Bunk #include <linux/fs.h> 371da177e4SLinus Torvalds #include <linux/init.h> 381da177e4SLinus Torvalds #include <linux/kernel.h> 390296b228SKay Sievers #include <linux/kobject.h> 4020380731SArnaldo Carvalho de Melo #include <linux/net.h> 411da177e4SLinus Torvalds #include <linux/sysrq.h> 421da177e4SLinus Torvalds #include <linux/highuid.h> 431da177e4SLinus Torvalds #include <linux/writeback.h> 443fff4c42SIngo Molnar #include <linux/ratelimit.h> 4576ab0f53SMel Gorman #include <linux/compaction.h> 461da177e4SLinus Torvalds #include <linux/hugetlb.h> 471da177e4SLinus Torvalds #include <linux/initrd.h> 480b77f5bfSDavid Howells #include <linux/key.h> 491da177e4SLinus Torvalds #include <linux/times.h> 501da177e4SLinus Torvalds #include <linux/limits.h> 511da177e4SLinus Torvalds #include <linux/dcache.h> 521da177e4SLinus Torvalds #include <linux/syscalls.h> 53c748e134SAdrian Bunk #include <linux/vmstat.h> 54c255d844SPavel Machek #include <linux/nfs_fs.h> 55c255d844SPavel Machek #include <linux/acpi.h> 5610a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h> 57b0fc494fSSteven Rostedt #include <linux/ftrace.h> 58cdd6c482SIngo Molnar #include <linux/perf_event.h> 598e4228e1SDavid Rientjes #include <linux/oom.h> 6017f60a7dSEric Paris #include <linux/kmod.h> 6173efc039SDan Ballard #include <linux/capability.h> 6240401530SAl Viro #include <linux/binfmts.h> 63cf4aebc2SClark Williams #include <linux/sched/sysctl.h> 64d2921684SEric W. Biederman #include <linux/mount.h> 65cefdca0aSPeter Xu #include <linux/userfaultfd_k.h> 662374c09bSChristoph Hellwig #include <linux/pid.h> 671da177e4SLinus Torvalds 687f2923c4SChristian Brauner #include "../lib/kstrtox.h" 697f2923c4SChristian Brauner 707c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 711da177e4SLinus Torvalds #include <asm/processor.h> 721da177e4SLinus Torvalds 7329cbc78bSAndi Kleen #ifdef CONFIG_X86 7429cbc78bSAndi Kleen #include <asm/nmi.h> 750741f4d2SChuck Ebbert #include <asm/stacktrace.h> 766e7c4025SIngo Molnar #include <asm/io.h> 7729cbc78bSAndi Kleen #endif 78d550bbd4SDavid Howells #ifdef CONFIG_SPARC 79d550bbd4SDavid Howells #include <asm/setup.h> 80d550bbd4SDavid Howells #endif 814f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES 824f0e056fSDave Young #include <linux/rtmutex.h> 834f0e056fSDave Young #endif 84504d7cf1SDon Zickus 851da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 861da177e4SLinus Torvalds 87c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 88c4f3b63fSRavikiran G Thirumalai 89c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS 90d73840ecSXiaoming Ni static const int six_hundred_forty_kb = 640 * 1024; 91c5dfd78eSArnaldo Carvalho de Melo #endif 92c4f3b63fSRavikiran G Thirumalai 939e4a5bdaSAndrea Righi 94f628867dSStephen Kitt static const int ngroups_max = NGROUPS_MAX; 9573efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP; 961da177e4SLinus Torvalds 97d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 98f4aacea2SKees Cook 99a19ac337SLuis R. Rodriguez /** 100a19ac337SLuis R. Rodriguez * enum sysctl_writes_mode - supported sysctl write modes 101a19ac337SLuis R. Rodriguez * 102a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value 103a19ac337SLuis R. Rodriguez * to be written, and multiple writes on the same sysctl file descriptor 104a19ac337SLuis R. Rodriguez * will rewrite the sysctl value, regardless of file position. No warning 105a19ac337SLuis R. Rodriguez * is issued when the initial position is not 0. 106a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is 107a19ac337SLuis R. Rodriguez * not 0. 108a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at 109a19ac337SLuis R. Rodriguez * file position 0 and the value must be fully contained in the buffer 110a19ac337SLuis R. Rodriguez * sent to the write syscall. If dealing with strings respect the file 111a19ac337SLuis R. Rodriguez * position, but restrict this to the max length of the buffer, anything 11265f50f25SWeitao Hou * passed the max length will be ignored. Multiple writes will append 113a19ac337SLuis R. Rodriguez * to the buffer. 114a19ac337SLuis R. Rodriguez * 115a19ac337SLuis R. Rodriguez * These write modes control how current file position affects the behavior of 116a19ac337SLuis R. Rodriguez * updating sysctl values through the proc interface on each write. 117a19ac337SLuis R. Rodriguez */ 118a19ac337SLuis R. Rodriguez enum sysctl_writes_mode { 119a19ac337SLuis R. Rodriguez SYSCTL_WRITES_LEGACY = -1, 120a19ac337SLuis R. Rodriguez SYSCTL_WRITES_WARN = 0, 121a19ac337SLuis R. Rodriguez SYSCTL_WRITES_STRICT = 1, 122a19ac337SLuis R. Rodriguez }; 123f4aacea2SKees Cook 124a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; 125f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */ 126ceb18132SLuis R. Rodriguez 12767f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ 12867f3977fSAlexandre Ghiti defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) 1291da177e4SLinus Torvalds int sysctl_legacy_va_layout; 1301da177e4SLinus Torvalds #endif 1311da177e4SLinus Torvalds 132f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */ 133f461d2dcSChristoph Hellwig 134f461d2dcSChristoph Hellwig /* 135f461d2dcSChristoph Hellwig * /proc/sys support 136f461d2dcSChristoph Hellwig */ 137f461d2dcSChristoph Hellwig 138f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL 139f461d2dcSChristoph Hellwig 140f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write, 14132927393SChristoph Hellwig char *buffer, size_t *lenp, loff_t *ppos) 142f461d2dcSChristoph Hellwig { 143f461d2dcSChristoph Hellwig size_t len; 14432927393SChristoph Hellwig char c, *p; 145f461d2dcSChristoph Hellwig 146f461d2dcSChristoph Hellwig if (!data || !maxlen || !*lenp) { 147f461d2dcSChristoph Hellwig *lenp = 0; 148f461d2dcSChristoph Hellwig return 0; 149f461d2dcSChristoph Hellwig } 150f461d2dcSChristoph Hellwig 151f461d2dcSChristoph Hellwig if (write) { 152f461d2dcSChristoph Hellwig if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) { 153f461d2dcSChristoph Hellwig /* Only continue writes not past the end of buffer. */ 154f461d2dcSChristoph Hellwig len = strlen(data); 155f461d2dcSChristoph Hellwig if (len > maxlen - 1) 156f461d2dcSChristoph Hellwig len = maxlen - 1; 157f461d2dcSChristoph Hellwig 158f461d2dcSChristoph Hellwig if (*ppos > len) 159f461d2dcSChristoph Hellwig return 0; 160f461d2dcSChristoph Hellwig len = *ppos; 161f461d2dcSChristoph Hellwig } else { 162f461d2dcSChristoph Hellwig /* Start writing from beginning of buffer. */ 163f461d2dcSChristoph Hellwig len = 0; 164f461d2dcSChristoph Hellwig } 165f461d2dcSChristoph Hellwig 166f461d2dcSChristoph Hellwig *ppos += *lenp; 167f461d2dcSChristoph Hellwig p = buffer; 168f461d2dcSChristoph Hellwig while ((p - buffer) < *lenp && len < maxlen - 1) { 16932927393SChristoph Hellwig c = *(p++); 170f461d2dcSChristoph Hellwig if (c == 0 || c == '\n') 171f461d2dcSChristoph Hellwig break; 172f461d2dcSChristoph Hellwig data[len++] = c; 173f461d2dcSChristoph Hellwig } 174f461d2dcSChristoph Hellwig data[len] = 0; 175f461d2dcSChristoph Hellwig } else { 176f461d2dcSChristoph Hellwig len = strlen(data); 177f461d2dcSChristoph Hellwig if (len > maxlen) 178f461d2dcSChristoph Hellwig len = maxlen; 179f461d2dcSChristoph Hellwig 180f461d2dcSChristoph Hellwig if (*ppos > len) { 181f461d2dcSChristoph Hellwig *lenp = 0; 182f461d2dcSChristoph Hellwig return 0; 183f461d2dcSChristoph Hellwig } 184f461d2dcSChristoph Hellwig 185f461d2dcSChristoph Hellwig data += *ppos; 186f461d2dcSChristoph Hellwig len -= *ppos; 187f461d2dcSChristoph Hellwig 188f461d2dcSChristoph Hellwig if (len > *lenp) 189f461d2dcSChristoph Hellwig len = *lenp; 190f461d2dcSChristoph Hellwig if (len) 19132927393SChristoph Hellwig memcpy(buffer, data, len); 192f461d2dcSChristoph Hellwig if (len < *lenp) { 19332927393SChristoph Hellwig buffer[len] = '\n'; 194f461d2dcSChristoph Hellwig len++; 195f461d2dcSChristoph Hellwig } 196f461d2dcSChristoph Hellwig *lenp = len; 197f461d2dcSChristoph Hellwig *ppos += len; 198f461d2dcSChristoph Hellwig } 199f461d2dcSChristoph Hellwig return 0; 200f461d2dcSChristoph Hellwig } 201f461d2dcSChristoph Hellwig 202f461d2dcSChristoph Hellwig static void warn_sysctl_write(struct ctl_table *table) 203f461d2dcSChristoph Hellwig { 204f461d2dcSChristoph Hellwig pr_warn_once("%s wrote to %s when file position was not 0!\n" 205f461d2dcSChristoph Hellwig "This will not be supported in the future. To silence this\n" 206f461d2dcSChristoph Hellwig "warning, set kernel.sysctl_writes_strict = -1\n", 207f461d2dcSChristoph Hellwig current->comm, table->procname); 208f461d2dcSChristoph Hellwig } 209f461d2dcSChristoph Hellwig 210f461d2dcSChristoph Hellwig /** 211f461d2dcSChristoph Hellwig * proc_first_pos_non_zero_ignore - check if first position is allowed 212f461d2dcSChristoph Hellwig * @ppos: file position 213f461d2dcSChristoph Hellwig * @table: the sysctl table 214f461d2dcSChristoph Hellwig * 215f461d2dcSChristoph Hellwig * Returns true if the first position is non-zero and the sysctl_writes_strict 216f461d2dcSChristoph Hellwig * mode indicates this is not allowed for numeric input types. String proc 217f461d2dcSChristoph Hellwig * handlers can ignore the return value. 218f461d2dcSChristoph Hellwig */ 219f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos, 220f461d2dcSChristoph Hellwig struct ctl_table *table) 221f461d2dcSChristoph Hellwig { 222f461d2dcSChristoph Hellwig if (!*ppos) 223f461d2dcSChristoph Hellwig return false; 224f461d2dcSChristoph Hellwig 225f461d2dcSChristoph Hellwig switch (sysctl_writes_strict) { 226f461d2dcSChristoph Hellwig case SYSCTL_WRITES_STRICT: 227f461d2dcSChristoph Hellwig return true; 228f461d2dcSChristoph Hellwig case SYSCTL_WRITES_WARN: 229f461d2dcSChristoph Hellwig warn_sysctl_write(table); 230f461d2dcSChristoph Hellwig return false; 231f461d2dcSChristoph Hellwig default: 232f461d2dcSChristoph Hellwig return false; 233f461d2dcSChristoph Hellwig } 234f461d2dcSChristoph Hellwig } 235f461d2dcSChristoph Hellwig 236f461d2dcSChristoph Hellwig /** 237f461d2dcSChristoph Hellwig * proc_dostring - read a string sysctl 238f461d2dcSChristoph Hellwig * @table: the sysctl table 239f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 240f461d2dcSChristoph Hellwig * @buffer: the user buffer 241f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 242f461d2dcSChristoph Hellwig * @ppos: file position 243f461d2dcSChristoph Hellwig * 244f461d2dcSChristoph Hellwig * Reads/writes a string from/to the user buffer. If the kernel 245f461d2dcSChristoph Hellwig * buffer provided is not large enough to hold the string, the 246f461d2dcSChristoph Hellwig * string is truncated. The copied string is %NULL-terminated. 247f461d2dcSChristoph Hellwig * If the string is being read by the user process, it is copied 248f461d2dcSChristoph Hellwig * and a newline '\n' is added. It is truncated if the buffer is 249f461d2dcSChristoph Hellwig * not large enough. 250f461d2dcSChristoph Hellwig * 251f461d2dcSChristoph Hellwig * Returns 0 on success. 252f461d2dcSChristoph Hellwig */ 253f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write, 25432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 255f461d2dcSChristoph Hellwig { 256f461d2dcSChristoph Hellwig if (write) 257f461d2dcSChristoph Hellwig proc_first_pos_non_zero_ignore(ppos, table); 258f461d2dcSChristoph Hellwig 25932927393SChristoph Hellwig return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, 26032927393SChristoph Hellwig ppos); 261f461d2dcSChristoph Hellwig } 262f461d2dcSChristoph Hellwig 263f461d2dcSChristoph Hellwig static size_t proc_skip_spaces(char **buf) 264f461d2dcSChristoph Hellwig { 265f461d2dcSChristoph Hellwig size_t ret; 266f461d2dcSChristoph Hellwig char *tmp = skip_spaces(*buf); 267f461d2dcSChristoph Hellwig ret = tmp - *buf; 268f461d2dcSChristoph Hellwig *buf = tmp; 269f461d2dcSChristoph Hellwig return ret; 270f461d2dcSChristoph Hellwig } 271f461d2dcSChristoph Hellwig 272f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v) 273f461d2dcSChristoph Hellwig { 274f461d2dcSChristoph Hellwig while (*size) { 275f461d2dcSChristoph Hellwig if (**buf != v) 276f461d2dcSChristoph Hellwig break; 277f461d2dcSChristoph Hellwig (*size)--; 278f461d2dcSChristoph Hellwig (*buf)++; 279f461d2dcSChristoph Hellwig } 280f461d2dcSChristoph Hellwig } 281f461d2dcSChristoph Hellwig 282f461d2dcSChristoph Hellwig /** 283f461d2dcSChristoph Hellwig * strtoul_lenient - parse an ASCII formatted integer from a buffer and only 284f461d2dcSChristoph Hellwig * fail on overflow 285f461d2dcSChristoph Hellwig * 286f461d2dcSChristoph Hellwig * @cp: kernel buffer containing the string to parse 287f461d2dcSChristoph Hellwig * @endp: pointer to store the trailing characters 288f461d2dcSChristoph Hellwig * @base: the base to use 289f461d2dcSChristoph Hellwig * @res: where the parsed integer will be stored 290f461d2dcSChristoph Hellwig * 291f461d2dcSChristoph Hellwig * In case of success 0 is returned and @res will contain the parsed integer, 292f461d2dcSChristoph Hellwig * @endp will hold any trailing characters. 293f461d2dcSChristoph Hellwig * This function will fail the parse on overflow. If there wasn't an overflow 294f461d2dcSChristoph Hellwig * the function will defer the decision what characters count as invalid to the 295f461d2dcSChristoph Hellwig * caller. 296f461d2dcSChristoph Hellwig */ 297f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base, 298f461d2dcSChristoph Hellwig unsigned long *res) 299f461d2dcSChristoph Hellwig { 300f461d2dcSChristoph Hellwig unsigned long long result; 301f461d2dcSChristoph Hellwig unsigned int rv; 302f461d2dcSChristoph Hellwig 303f461d2dcSChristoph Hellwig cp = _parse_integer_fixup_radix(cp, &base); 304f461d2dcSChristoph Hellwig rv = _parse_integer(cp, base, &result); 305f461d2dcSChristoph Hellwig if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result)) 306f461d2dcSChristoph Hellwig return -ERANGE; 307f461d2dcSChristoph Hellwig 308f461d2dcSChristoph Hellwig cp += rv; 309f461d2dcSChristoph Hellwig 310f461d2dcSChristoph Hellwig if (endp) 311f461d2dcSChristoph Hellwig *endp = (char *)cp; 312f461d2dcSChristoph Hellwig 313f461d2dcSChristoph Hellwig *res = (unsigned long)result; 314f461d2dcSChristoph Hellwig return 0; 315f461d2dcSChristoph Hellwig } 316f461d2dcSChristoph Hellwig 317f461d2dcSChristoph Hellwig #define TMPBUFLEN 22 318f461d2dcSChristoph Hellwig /** 319f461d2dcSChristoph Hellwig * proc_get_long - reads an ASCII formatted integer from a user buffer 320f461d2dcSChristoph Hellwig * 321f461d2dcSChristoph Hellwig * @buf: a kernel buffer 322f461d2dcSChristoph Hellwig * @size: size of the kernel buffer 323f461d2dcSChristoph Hellwig * @val: this is where the number will be stored 324f461d2dcSChristoph Hellwig * @neg: set to %TRUE if number is negative 325f461d2dcSChristoph Hellwig * @perm_tr: a vector which contains the allowed trailers 326f461d2dcSChristoph Hellwig * @perm_tr_len: size of the perm_tr vector 327f461d2dcSChristoph Hellwig * @tr: pointer to store the trailer character 328f461d2dcSChristoph Hellwig * 329f461d2dcSChristoph Hellwig * In case of success %0 is returned and @buf and @size are updated with 330f461d2dcSChristoph Hellwig * the amount of bytes read. If @tr is non-NULL and a trailing 331f461d2dcSChristoph Hellwig * character exists (size is non-zero after returning from this 332f461d2dcSChristoph Hellwig * function), @tr is updated with the trailing character. 333f461d2dcSChristoph Hellwig */ 334f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size, 335f461d2dcSChristoph Hellwig unsigned long *val, bool *neg, 336f461d2dcSChristoph Hellwig const char *perm_tr, unsigned perm_tr_len, char *tr) 337f461d2dcSChristoph Hellwig { 338f461d2dcSChristoph Hellwig int len; 339f461d2dcSChristoph Hellwig char *p, tmp[TMPBUFLEN]; 340f461d2dcSChristoph Hellwig 341f461d2dcSChristoph Hellwig if (!*size) 342f461d2dcSChristoph Hellwig return -EINVAL; 343f461d2dcSChristoph Hellwig 344f461d2dcSChristoph Hellwig len = *size; 345f461d2dcSChristoph Hellwig if (len > TMPBUFLEN - 1) 346f461d2dcSChristoph Hellwig len = TMPBUFLEN - 1; 347f461d2dcSChristoph Hellwig 348f461d2dcSChristoph Hellwig memcpy(tmp, *buf, len); 349f461d2dcSChristoph Hellwig 350f461d2dcSChristoph Hellwig tmp[len] = 0; 351f461d2dcSChristoph Hellwig p = tmp; 352f461d2dcSChristoph Hellwig if (*p == '-' && *size > 1) { 353f461d2dcSChristoph Hellwig *neg = true; 354f461d2dcSChristoph Hellwig p++; 355f461d2dcSChristoph Hellwig } else 356f461d2dcSChristoph Hellwig *neg = false; 357f461d2dcSChristoph Hellwig if (!isdigit(*p)) 358f461d2dcSChristoph Hellwig return -EINVAL; 359f461d2dcSChristoph Hellwig 360f461d2dcSChristoph Hellwig if (strtoul_lenient(p, &p, 0, val)) 361f461d2dcSChristoph Hellwig return -EINVAL; 362f461d2dcSChristoph Hellwig 363f461d2dcSChristoph Hellwig len = p - tmp; 364f461d2dcSChristoph Hellwig 365f461d2dcSChristoph Hellwig /* We don't know if the next char is whitespace thus we may accept 366f461d2dcSChristoph Hellwig * invalid integers (e.g. 1234...a) or two integers instead of one 367f461d2dcSChristoph Hellwig * (e.g. 123...1). So lets not allow such large numbers. */ 368f461d2dcSChristoph Hellwig if (len == TMPBUFLEN - 1) 369f461d2dcSChristoph Hellwig return -EINVAL; 370f461d2dcSChristoph Hellwig 371f461d2dcSChristoph Hellwig if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) 372f461d2dcSChristoph Hellwig return -EINVAL; 373f461d2dcSChristoph Hellwig 374f461d2dcSChristoph Hellwig if (tr && (len < *size)) 375f461d2dcSChristoph Hellwig *tr = *p; 376f461d2dcSChristoph Hellwig 377f461d2dcSChristoph Hellwig *buf += len; 378f461d2dcSChristoph Hellwig *size -= len; 379f461d2dcSChristoph Hellwig 380f461d2dcSChristoph Hellwig return 0; 381f461d2dcSChristoph Hellwig } 382f461d2dcSChristoph Hellwig 383f461d2dcSChristoph Hellwig /** 384f461d2dcSChristoph Hellwig * proc_put_long - converts an integer to a decimal ASCII formatted string 385f461d2dcSChristoph Hellwig * 386f461d2dcSChristoph Hellwig * @buf: the user buffer 387f461d2dcSChristoph Hellwig * @size: the size of the user buffer 388f461d2dcSChristoph Hellwig * @val: the integer to be converted 389f461d2dcSChristoph Hellwig * @neg: sign of the number, %TRUE for negative 390f461d2dcSChristoph Hellwig * 39132927393SChristoph Hellwig * In case of success @buf and @size are updated with the amount of bytes 39232927393SChristoph Hellwig * written. 393f461d2dcSChristoph Hellwig */ 39432927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) 395f461d2dcSChristoph Hellwig { 396f461d2dcSChristoph Hellwig int len; 397f461d2dcSChristoph Hellwig char tmp[TMPBUFLEN], *p = tmp; 398f461d2dcSChristoph Hellwig 399f461d2dcSChristoph Hellwig sprintf(p, "%s%lu", neg ? "-" : "", val); 400f461d2dcSChristoph Hellwig len = strlen(tmp); 401f461d2dcSChristoph Hellwig if (len > *size) 402f461d2dcSChristoph Hellwig len = *size; 40332927393SChristoph Hellwig memcpy(*buf, tmp, len); 404f461d2dcSChristoph Hellwig *size -= len; 405f461d2dcSChristoph Hellwig *buf += len; 406f461d2dcSChristoph Hellwig } 407f461d2dcSChristoph Hellwig #undef TMPBUFLEN 408f461d2dcSChristoph Hellwig 40932927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c) 410f461d2dcSChristoph Hellwig { 411f461d2dcSChristoph Hellwig if (*size) { 41232927393SChristoph Hellwig char **buffer = (char **)buf; 41332927393SChristoph Hellwig **buffer = c; 41432927393SChristoph Hellwig 41532927393SChristoph Hellwig (*size)--; 41632927393SChristoph Hellwig (*buffer)++; 417f461d2dcSChristoph Hellwig *buf = *buffer; 418f461d2dcSChristoph Hellwig } 419f461d2dcSChristoph Hellwig } 420f461d2dcSChristoph Hellwig 421a2071573SJia He static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp, 422a2071573SJia He int *valp, 423a2071573SJia He int write, void *data) 424a2071573SJia He { 425a2071573SJia He if (write) { 426a2071573SJia He *(bool *)valp = *lvalp; 427a2071573SJia He } else { 428a2071573SJia He int val = *(bool *)valp; 429a2071573SJia He 430a2071573SJia He *lvalp = (unsigned long)val; 431a2071573SJia He *negp = false; 432a2071573SJia He } 433a2071573SJia He return 0; 434a2071573SJia He } 435a2071573SJia He 436f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 437f461d2dcSChristoph Hellwig int *valp, 438f461d2dcSChristoph Hellwig int write, void *data) 439f461d2dcSChristoph Hellwig { 440f461d2dcSChristoph Hellwig if (write) { 441f461d2dcSChristoph Hellwig if (*negp) { 442f461d2dcSChristoph Hellwig if (*lvalp > (unsigned long) INT_MAX + 1) 443f461d2dcSChristoph Hellwig return -EINVAL; 4441f1be04bSKuniyuki Iwashima WRITE_ONCE(*valp, -*lvalp); 445f461d2dcSChristoph Hellwig } else { 446f461d2dcSChristoph Hellwig if (*lvalp > (unsigned long) INT_MAX) 447f461d2dcSChristoph Hellwig return -EINVAL; 4481f1be04bSKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp); 449f461d2dcSChristoph Hellwig } 450f461d2dcSChristoph Hellwig } else { 4511f1be04bSKuniyuki Iwashima int val = READ_ONCE(*valp); 452f461d2dcSChristoph Hellwig if (val < 0) { 453f461d2dcSChristoph Hellwig *negp = true; 454f461d2dcSChristoph Hellwig *lvalp = -(unsigned long)val; 455f461d2dcSChristoph Hellwig } else { 456f461d2dcSChristoph Hellwig *negp = false; 457f461d2dcSChristoph Hellwig *lvalp = (unsigned long)val; 458f461d2dcSChristoph Hellwig } 459f461d2dcSChristoph Hellwig } 460f461d2dcSChristoph Hellwig return 0; 461f461d2dcSChristoph Hellwig } 462f461d2dcSChristoph Hellwig 463f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp, 464f461d2dcSChristoph Hellwig unsigned int *valp, 465f461d2dcSChristoph Hellwig int write, void *data) 466f461d2dcSChristoph Hellwig { 467f461d2dcSChristoph Hellwig if (write) { 468f461d2dcSChristoph Hellwig if (*lvalp > UINT_MAX) 469f461d2dcSChristoph Hellwig return -EINVAL; 4704762b532SKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp); 471f461d2dcSChristoph Hellwig } else { 4724762b532SKuniyuki Iwashima unsigned int val = READ_ONCE(*valp); 473f461d2dcSChristoph Hellwig *lvalp = (unsigned long)val; 474f461d2dcSChristoph Hellwig } 475f461d2dcSChristoph Hellwig return 0; 476f461d2dcSChristoph Hellwig } 477f461d2dcSChristoph Hellwig 478f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; 479f461d2dcSChristoph Hellwig 480f461d2dcSChristoph Hellwig static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 48132927393SChristoph Hellwig int write, void *buffer, 482f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 483f461d2dcSChristoph Hellwig int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 484f461d2dcSChristoph Hellwig int write, void *data), 485f461d2dcSChristoph Hellwig void *data) 486f461d2dcSChristoph Hellwig { 487f461d2dcSChristoph Hellwig int *i, vleft, first = 1, err = 0; 488f461d2dcSChristoph Hellwig size_t left; 48932927393SChristoph Hellwig char *p; 490f461d2dcSChristoph Hellwig 491f461d2dcSChristoph Hellwig if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 492f461d2dcSChristoph Hellwig *lenp = 0; 493f461d2dcSChristoph Hellwig return 0; 494f461d2dcSChristoph Hellwig } 495f461d2dcSChristoph Hellwig 496f461d2dcSChristoph Hellwig i = (int *) tbl_data; 497f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(*i); 498f461d2dcSChristoph Hellwig left = *lenp; 499f461d2dcSChristoph Hellwig 500f461d2dcSChristoph Hellwig if (!conv) 501f461d2dcSChristoph Hellwig conv = do_proc_dointvec_conv; 502f461d2dcSChristoph Hellwig 503f461d2dcSChristoph Hellwig if (write) { 504f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table)) 505f461d2dcSChristoph Hellwig goto out; 506f461d2dcSChristoph Hellwig 507f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) 508f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 50932927393SChristoph Hellwig p = buffer; 510f461d2dcSChristoph Hellwig } 511f461d2dcSChristoph Hellwig 512f461d2dcSChristoph Hellwig for (; left && vleft--; i++, first=0) { 513f461d2dcSChristoph Hellwig unsigned long lval; 514f461d2dcSChristoph Hellwig bool neg; 515f461d2dcSChristoph Hellwig 516f461d2dcSChristoph Hellwig if (write) { 517f461d2dcSChristoph Hellwig left -= proc_skip_spaces(&p); 518f461d2dcSChristoph Hellwig 519f461d2dcSChristoph Hellwig if (!left) 520f461d2dcSChristoph Hellwig break; 521f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &lval, &neg, 522f461d2dcSChristoph Hellwig proc_wspace_sep, 523f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL); 524f461d2dcSChristoph Hellwig if (err) 525f461d2dcSChristoph Hellwig break; 526f461d2dcSChristoph Hellwig if (conv(&neg, &lval, i, 1, data)) { 527f461d2dcSChristoph Hellwig err = -EINVAL; 528f461d2dcSChristoph Hellwig break; 529f461d2dcSChristoph Hellwig } 530f461d2dcSChristoph Hellwig } else { 531f461d2dcSChristoph Hellwig if (conv(&neg, &lval, i, 0, data)) { 532f461d2dcSChristoph Hellwig err = -EINVAL; 533f461d2dcSChristoph Hellwig break; 534f461d2dcSChristoph Hellwig } 535f461d2dcSChristoph Hellwig if (!first) 53632927393SChristoph Hellwig proc_put_char(&buffer, &left, '\t'); 53732927393SChristoph Hellwig proc_put_long(&buffer, &left, lval, neg); 538f461d2dcSChristoph Hellwig } 539f461d2dcSChristoph Hellwig } 540f461d2dcSChristoph Hellwig 541f461d2dcSChristoph Hellwig if (!write && !first && left && !err) 54232927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 543f461d2dcSChristoph Hellwig if (write && !err && left) 544f461d2dcSChristoph Hellwig left -= proc_skip_spaces(&p); 54532927393SChristoph Hellwig if (write && first) 546f461d2dcSChristoph Hellwig return err ? : -EINVAL; 547f461d2dcSChristoph Hellwig *lenp -= left; 548f461d2dcSChristoph Hellwig out: 549f461d2dcSChristoph Hellwig *ppos += *lenp; 550f461d2dcSChristoph Hellwig return err; 551f461d2dcSChristoph Hellwig } 552f461d2dcSChristoph Hellwig 553f461d2dcSChristoph Hellwig static int do_proc_dointvec(struct ctl_table *table, int write, 55432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, 555f461d2dcSChristoph Hellwig int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 556f461d2dcSChristoph Hellwig int write, void *data), 557f461d2dcSChristoph Hellwig void *data) 558f461d2dcSChristoph Hellwig { 559f461d2dcSChristoph Hellwig return __do_proc_dointvec(table->data, table, write, 560f461d2dcSChristoph Hellwig buffer, lenp, ppos, conv, data); 561f461d2dcSChristoph Hellwig } 562f461d2dcSChristoph Hellwig 563f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data, 564f461d2dcSChristoph Hellwig struct ctl_table *table, 56532927393SChristoph Hellwig void *buffer, 566f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 567f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 568f461d2dcSChristoph Hellwig unsigned int *valp, 569f461d2dcSChristoph Hellwig int write, void *data), 570f461d2dcSChristoph Hellwig void *data) 571f461d2dcSChristoph Hellwig { 572f461d2dcSChristoph Hellwig unsigned long lval; 573f461d2dcSChristoph Hellwig int err = 0; 574f461d2dcSChristoph Hellwig size_t left; 575f461d2dcSChristoph Hellwig bool neg; 57632927393SChristoph Hellwig char *p = buffer; 577f461d2dcSChristoph Hellwig 578f461d2dcSChristoph Hellwig left = *lenp; 579f461d2dcSChristoph Hellwig 580f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table)) 581f461d2dcSChristoph Hellwig goto bail_early; 582f461d2dcSChristoph Hellwig 583f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) 584f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 585f461d2dcSChristoph Hellwig 586f461d2dcSChristoph Hellwig left -= proc_skip_spaces(&p); 587f461d2dcSChristoph Hellwig if (!left) { 588f461d2dcSChristoph Hellwig err = -EINVAL; 589f461d2dcSChristoph Hellwig goto out_free; 590f461d2dcSChristoph Hellwig } 591f461d2dcSChristoph Hellwig 592f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &lval, &neg, 593f461d2dcSChristoph Hellwig proc_wspace_sep, 594f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL); 595f461d2dcSChristoph Hellwig if (err || neg) { 596f461d2dcSChristoph Hellwig err = -EINVAL; 597f461d2dcSChristoph Hellwig goto out_free; 598f461d2dcSChristoph Hellwig } 599f461d2dcSChristoph Hellwig 600f461d2dcSChristoph Hellwig if (conv(&lval, tbl_data, 1, data)) { 601f461d2dcSChristoph Hellwig err = -EINVAL; 602f461d2dcSChristoph Hellwig goto out_free; 603f461d2dcSChristoph Hellwig } 604f461d2dcSChristoph Hellwig 605f461d2dcSChristoph Hellwig if (!err && left) 606f461d2dcSChristoph Hellwig left -= proc_skip_spaces(&p); 607f461d2dcSChristoph Hellwig 608f461d2dcSChristoph Hellwig out_free: 609f461d2dcSChristoph Hellwig if (err) 610f461d2dcSChristoph Hellwig return -EINVAL; 611f461d2dcSChristoph Hellwig 612f461d2dcSChristoph Hellwig return 0; 613f461d2dcSChristoph Hellwig 614f461d2dcSChristoph Hellwig /* This is in keeping with old __do_proc_dointvec() */ 615f461d2dcSChristoph Hellwig bail_early: 616f461d2dcSChristoph Hellwig *ppos += *lenp; 617f461d2dcSChristoph Hellwig return err; 618f461d2dcSChristoph Hellwig } 619f461d2dcSChristoph Hellwig 62032927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer, 621f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 622f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 623f461d2dcSChristoph Hellwig unsigned int *valp, 624f461d2dcSChristoph Hellwig int write, void *data), 625f461d2dcSChristoph Hellwig void *data) 626f461d2dcSChristoph Hellwig { 627f461d2dcSChristoph Hellwig unsigned long lval; 628f461d2dcSChristoph Hellwig int err = 0; 629f461d2dcSChristoph Hellwig size_t left; 630f461d2dcSChristoph Hellwig 631f461d2dcSChristoph Hellwig left = *lenp; 632f461d2dcSChristoph Hellwig 633f461d2dcSChristoph Hellwig if (conv(&lval, tbl_data, 0, data)) { 634f461d2dcSChristoph Hellwig err = -EINVAL; 635f461d2dcSChristoph Hellwig goto out; 636f461d2dcSChristoph Hellwig } 637f461d2dcSChristoph Hellwig 63832927393SChristoph Hellwig proc_put_long(&buffer, &left, lval, false); 63932927393SChristoph Hellwig if (!left) 640f461d2dcSChristoph Hellwig goto out; 641f461d2dcSChristoph Hellwig 64232927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 643f461d2dcSChristoph Hellwig 644f461d2dcSChristoph Hellwig out: 645f461d2dcSChristoph Hellwig *lenp -= left; 646f461d2dcSChristoph Hellwig *ppos += *lenp; 647f461d2dcSChristoph Hellwig 648f461d2dcSChristoph Hellwig return err; 649f461d2dcSChristoph Hellwig } 650f461d2dcSChristoph Hellwig 651f461d2dcSChristoph Hellwig static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table, 65232927393SChristoph Hellwig int write, void *buffer, 653f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 654f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 655f461d2dcSChristoph Hellwig unsigned int *valp, 656f461d2dcSChristoph Hellwig int write, void *data), 657f461d2dcSChristoph Hellwig void *data) 658f461d2dcSChristoph Hellwig { 659f461d2dcSChristoph Hellwig unsigned int *i, vleft; 660f461d2dcSChristoph Hellwig 661f461d2dcSChristoph Hellwig if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 662f461d2dcSChristoph Hellwig *lenp = 0; 663f461d2dcSChristoph Hellwig return 0; 664f461d2dcSChristoph Hellwig } 665f461d2dcSChristoph Hellwig 666f461d2dcSChristoph Hellwig i = (unsigned int *) tbl_data; 667f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(*i); 668f461d2dcSChristoph Hellwig 669f461d2dcSChristoph Hellwig /* 670f461d2dcSChristoph Hellwig * Arrays are not supported, keep this simple. *Do not* add 671f461d2dcSChristoph Hellwig * support for them. 672f461d2dcSChristoph Hellwig */ 673f461d2dcSChristoph Hellwig if (vleft != 1) { 674f461d2dcSChristoph Hellwig *lenp = 0; 675f461d2dcSChristoph Hellwig return -EINVAL; 676f461d2dcSChristoph Hellwig } 677f461d2dcSChristoph Hellwig 678f461d2dcSChristoph Hellwig if (!conv) 679f461d2dcSChristoph Hellwig conv = do_proc_douintvec_conv; 680f461d2dcSChristoph Hellwig 681f461d2dcSChristoph Hellwig if (write) 682f461d2dcSChristoph Hellwig return do_proc_douintvec_w(i, table, buffer, lenp, ppos, 683f461d2dcSChristoph Hellwig conv, data); 684f461d2dcSChristoph Hellwig return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data); 685f461d2dcSChristoph Hellwig } 686f461d2dcSChristoph Hellwig 6871998f193SLuis Chamberlain int do_proc_douintvec(struct ctl_table *table, int write, 68832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, 689f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 690f461d2dcSChristoph Hellwig unsigned int *valp, 691f461d2dcSChristoph Hellwig int write, void *data), 692f461d2dcSChristoph Hellwig void *data) 693f461d2dcSChristoph Hellwig { 694f461d2dcSChristoph Hellwig return __do_proc_douintvec(table->data, table, write, 695f461d2dcSChristoph Hellwig buffer, lenp, ppos, conv, data); 696f461d2dcSChristoph Hellwig } 697f461d2dcSChristoph Hellwig 698f461d2dcSChristoph Hellwig /** 699a2071573SJia He * proc_dobool - read/write a bool 700a2071573SJia He * @table: the sysctl table 701a2071573SJia He * @write: %TRUE if this is a write to the sysctl file 702a2071573SJia He * @buffer: the user buffer 703a2071573SJia He * @lenp: the size of the user buffer 704a2071573SJia He * @ppos: file position 705a2071573SJia He * 706a2071573SJia He * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 707a2071573SJia He * values from/to the user buffer, treated as an ASCII string. 708a2071573SJia He * 709a2071573SJia He * Returns 0 on success. 710a2071573SJia He */ 711a2071573SJia He int proc_dobool(struct ctl_table *table, int write, void *buffer, 712a2071573SJia He size_t *lenp, loff_t *ppos) 713a2071573SJia He { 714a2071573SJia He return do_proc_dointvec(table, write, buffer, lenp, ppos, 715a2071573SJia He do_proc_dobool_conv, NULL); 716a2071573SJia He } 717a2071573SJia He 718a2071573SJia He /** 719f461d2dcSChristoph Hellwig * proc_dointvec - read a vector of integers 720f461d2dcSChristoph Hellwig * @table: the sysctl table 721f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 722f461d2dcSChristoph Hellwig * @buffer: the user buffer 723f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 724f461d2dcSChristoph Hellwig * @ppos: file position 725f461d2dcSChristoph Hellwig * 726f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 727f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 728f461d2dcSChristoph Hellwig * 729f461d2dcSChristoph Hellwig * Returns 0 on success. 730f461d2dcSChristoph Hellwig */ 73132927393SChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, void *buffer, 73232927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 733f461d2dcSChristoph Hellwig { 734f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); 735f461d2dcSChristoph Hellwig } 736f461d2dcSChristoph Hellwig 737f461d2dcSChristoph Hellwig #ifdef CONFIG_COMPACTION 738f461d2dcSChristoph Hellwig static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table, 73932927393SChristoph Hellwig int write, void *buffer, size_t *lenp, loff_t *ppos) 740f461d2dcSChristoph Hellwig { 741f461d2dcSChristoph Hellwig int ret, old; 742f461d2dcSChristoph Hellwig 743f461d2dcSChristoph Hellwig if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write) 744f461d2dcSChristoph Hellwig return proc_dointvec_minmax(table, write, buffer, lenp, ppos); 745f461d2dcSChristoph Hellwig 746f461d2dcSChristoph Hellwig old = *(int *)table->data; 747f461d2dcSChristoph Hellwig ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); 748f461d2dcSChristoph Hellwig if (ret) 749f461d2dcSChristoph Hellwig return ret; 750f461d2dcSChristoph Hellwig if (old != *(int *)table->data) 751f461d2dcSChristoph Hellwig pr_warn_once("sysctl attribute %s changed by %s[%d]\n", 752f461d2dcSChristoph Hellwig table->procname, current->comm, 753f461d2dcSChristoph Hellwig task_pid_nr(current)); 754f461d2dcSChristoph Hellwig return ret; 755f461d2dcSChristoph Hellwig } 756f461d2dcSChristoph Hellwig #endif 757f461d2dcSChristoph Hellwig 758f461d2dcSChristoph Hellwig /** 759f461d2dcSChristoph Hellwig * proc_douintvec - read a vector of unsigned integers 760f461d2dcSChristoph Hellwig * @table: the sysctl table 761f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 762f461d2dcSChristoph Hellwig * @buffer: the user buffer 763f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 764f461d2dcSChristoph Hellwig * @ppos: file position 765f461d2dcSChristoph Hellwig * 766f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer 767f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 768f461d2dcSChristoph Hellwig * 769f461d2dcSChristoph Hellwig * Returns 0 on success. 770f461d2dcSChristoph Hellwig */ 77132927393SChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, void *buffer, 77232927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 773f461d2dcSChristoph Hellwig { 774f461d2dcSChristoph Hellwig return do_proc_douintvec(table, write, buffer, lenp, ppos, 775f461d2dcSChristoph Hellwig do_proc_douintvec_conv, NULL); 776f461d2dcSChristoph Hellwig } 777f461d2dcSChristoph Hellwig 778f461d2dcSChristoph Hellwig /* 779f461d2dcSChristoph Hellwig * Taint values can only be increased 780f461d2dcSChristoph Hellwig * This means we can safely use a temporary. 781f461d2dcSChristoph Hellwig */ 782f461d2dcSChristoph Hellwig static int proc_taint(struct ctl_table *table, int write, 78332927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 784f461d2dcSChristoph Hellwig { 785f461d2dcSChristoph Hellwig struct ctl_table t; 786f461d2dcSChristoph Hellwig unsigned long tmptaint = get_taint(); 787f461d2dcSChristoph Hellwig int err; 788f461d2dcSChristoph Hellwig 789f461d2dcSChristoph Hellwig if (write && !capable(CAP_SYS_ADMIN)) 790f461d2dcSChristoph Hellwig return -EPERM; 791f461d2dcSChristoph Hellwig 792f461d2dcSChristoph Hellwig t = *table; 793f461d2dcSChristoph Hellwig t.data = &tmptaint; 794f461d2dcSChristoph Hellwig err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); 795f461d2dcSChristoph Hellwig if (err < 0) 796f461d2dcSChristoph Hellwig return err; 797f461d2dcSChristoph Hellwig 798f461d2dcSChristoph Hellwig if (write) { 799db38d5c1SRafael Aquini int i; 800db38d5c1SRafael Aquini 801db38d5c1SRafael Aquini /* 802db38d5c1SRafael Aquini * If we are relying on panic_on_taint not producing 803db38d5c1SRafael Aquini * false positives due to userspace input, bail out 804db38d5c1SRafael Aquini * before setting the requested taint flags. 805db38d5c1SRafael Aquini */ 806db38d5c1SRafael Aquini if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint)) 807db38d5c1SRafael Aquini return -EINVAL; 808db38d5c1SRafael Aquini 809f461d2dcSChristoph Hellwig /* 810f461d2dcSChristoph Hellwig * Poor man's atomic or. Not worth adding a primitive 811f461d2dcSChristoph Hellwig * to everyone's atomic.h for this 812f461d2dcSChristoph Hellwig */ 813e77132e7SRafael Aquini for (i = 0; i < TAINT_FLAGS_COUNT; i++) 814e77132e7SRafael Aquini if ((1UL << i) & tmptaint) 815f461d2dcSChristoph Hellwig add_taint(i, LOCKDEP_STILL_OK); 816f461d2dcSChristoph Hellwig } 817f461d2dcSChristoph Hellwig 818f461d2dcSChristoph Hellwig return err; 819f461d2dcSChristoph Hellwig } 820f461d2dcSChristoph Hellwig 821f461d2dcSChristoph Hellwig /** 822f461d2dcSChristoph Hellwig * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure 823f461d2dcSChristoph Hellwig * @min: pointer to minimum allowable value 824f461d2dcSChristoph Hellwig * @max: pointer to maximum allowable value 825f461d2dcSChristoph Hellwig * 826f461d2dcSChristoph Hellwig * The do_proc_dointvec_minmax_conv_param structure provides the 827f461d2dcSChristoph Hellwig * minimum and maximum values for doing range checking for those sysctl 828f461d2dcSChristoph Hellwig * parameters that use the proc_dointvec_minmax() handler. 829f461d2dcSChristoph Hellwig */ 830f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param { 831f461d2dcSChristoph Hellwig int *min; 832f461d2dcSChristoph Hellwig int *max; 833f461d2dcSChristoph Hellwig }; 834f461d2dcSChristoph Hellwig 835f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, 836f461d2dcSChristoph Hellwig int *valp, 837f461d2dcSChristoph Hellwig int write, void *data) 838f461d2dcSChristoph Hellwig { 839f461d2dcSChristoph Hellwig int tmp, ret; 840f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param *param = data; 841f461d2dcSChristoph Hellwig /* 842f461d2dcSChristoph Hellwig * If writing, first do so via a temporary local int so we can 843f461d2dcSChristoph Hellwig * bounds-check it before touching *valp. 844f461d2dcSChristoph Hellwig */ 845f461d2dcSChristoph Hellwig int *ip = write ? &tmp : valp; 846f461d2dcSChristoph Hellwig 847f461d2dcSChristoph Hellwig ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data); 848f461d2dcSChristoph Hellwig if (ret) 849f461d2dcSChristoph Hellwig return ret; 850f461d2dcSChristoph Hellwig 851f461d2dcSChristoph Hellwig if (write) { 852f461d2dcSChristoph Hellwig if ((param->min && *param->min > tmp) || 853f461d2dcSChristoph Hellwig (param->max && *param->max < tmp)) 854f461d2dcSChristoph Hellwig return -EINVAL; 855f613d86dSKuniyuki Iwashima WRITE_ONCE(*valp, tmp); 856f461d2dcSChristoph Hellwig } 857f461d2dcSChristoph Hellwig 858f461d2dcSChristoph Hellwig return 0; 859f461d2dcSChristoph Hellwig } 860f461d2dcSChristoph Hellwig 861f461d2dcSChristoph Hellwig /** 862f461d2dcSChristoph Hellwig * proc_dointvec_minmax - read a vector of integers with min/max values 863f461d2dcSChristoph Hellwig * @table: the sysctl table 864f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 865f461d2dcSChristoph Hellwig * @buffer: the user buffer 866f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 867f461d2dcSChristoph Hellwig * @ppos: file position 868f461d2dcSChristoph Hellwig * 869f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 870f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 871f461d2dcSChristoph Hellwig * 872f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 873f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). 874f461d2dcSChristoph Hellwig * 875f461d2dcSChristoph Hellwig * Returns 0 on success or -EINVAL on write when the range check fails. 876f461d2dcSChristoph Hellwig */ 877f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write, 87832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 879f461d2dcSChristoph Hellwig { 880f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param param = { 881f461d2dcSChristoph Hellwig .min = (int *) table->extra1, 882f461d2dcSChristoph Hellwig .max = (int *) table->extra2, 883f461d2dcSChristoph Hellwig }; 884f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, 885f461d2dcSChristoph Hellwig do_proc_dointvec_minmax_conv, ¶m); 886f461d2dcSChristoph Hellwig } 887f461d2dcSChristoph Hellwig 888f461d2dcSChristoph Hellwig /** 889f461d2dcSChristoph Hellwig * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure 890f461d2dcSChristoph Hellwig * @min: pointer to minimum allowable value 891f461d2dcSChristoph Hellwig * @max: pointer to maximum allowable value 892f461d2dcSChristoph Hellwig * 893f461d2dcSChristoph Hellwig * The do_proc_douintvec_minmax_conv_param structure provides the 894f461d2dcSChristoph Hellwig * minimum and maximum values for doing range checking for those sysctl 895f461d2dcSChristoph Hellwig * parameters that use the proc_douintvec_minmax() handler. 896f461d2dcSChristoph Hellwig */ 897f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param { 898f461d2dcSChristoph Hellwig unsigned int *min; 899f461d2dcSChristoph Hellwig unsigned int *max; 900f461d2dcSChristoph Hellwig }; 901f461d2dcSChristoph Hellwig 902f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, 903f461d2dcSChristoph Hellwig unsigned int *valp, 904f461d2dcSChristoph Hellwig int write, void *data) 905f461d2dcSChristoph Hellwig { 906f461d2dcSChristoph Hellwig int ret; 907f461d2dcSChristoph Hellwig unsigned int tmp; 908f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param *param = data; 909f461d2dcSChristoph Hellwig /* write via temporary local uint for bounds-checking */ 910f461d2dcSChristoph Hellwig unsigned int *up = write ? &tmp : valp; 911f461d2dcSChristoph Hellwig 912f461d2dcSChristoph Hellwig ret = do_proc_douintvec_conv(lvalp, up, write, data); 913f461d2dcSChristoph Hellwig if (ret) 914f461d2dcSChristoph Hellwig return ret; 915f461d2dcSChristoph Hellwig 916f461d2dcSChristoph Hellwig if (write) { 917f461d2dcSChristoph Hellwig if ((param->min && *param->min > tmp) || 918f461d2dcSChristoph Hellwig (param->max && *param->max < tmp)) 919f461d2dcSChristoph Hellwig return -ERANGE; 920f461d2dcSChristoph Hellwig 9212d3b559dSKuniyuki Iwashima WRITE_ONCE(*valp, tmp); 922f461d2dcSChristoph Hellwig } 923f461d2dcSChristoph Hellwig 924f461d2dcSChristoph Hellwig return 0; 925f461d2dcSChristoph Hellwig } 926f461d2dcSChristoph Hellwig 927f461d2dcSChristoph Hellwig /** 928f461d2dcSChristoph Hellwig * proc_douintvec_minmax - read a vector of unsigned ints with min/max values 929f461d2dcSChristoph Hellwig * @table: the sysctl table 930f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 931f461d2dcSChristoph Hellwig * @buffer: the user buffer 932f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 933f461d2dcSChristoph Hellwig * @ppos: file position 934f461d2dcSChristoph Hellwig * 935f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer 936f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. Negative 937f461d2dcSChristoph Hellwig * strings are not allowed. 938f461d2dcSChristoph Hellwig * 939f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 940f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). There is a final sanity 941f461d2dcSChristoph Hellwig * check for UINT_MAX to avoid having to support wrap around uses from 942f461d2dcSChristoph Hellwig * userspace. 943f461d2dcSChristoph Hellwig * 944f461d2dcSChristoph Hellwig * Returns 0 on success or -ERANGE on write when the range check fails. 945f461d2dcSChristoph Hellwig */ 946f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write, 94732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 948f461d2dcSChristoph Hellwig { 949f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param param = { 950f461d2dcSChristoph Hellwig .min = (unsigned int *) table->extra1, 951f461d2dcSChristoph Hellwig .max = (unsigned int *) table->extra2, 952f461d2dcSChristoph Hellwig }; 953f461d2dcSChristoph Hellwig return do_proc_douintvec(table, write, buffer, lenp, ppos, 954f461d2dcSChristoph Hellwig do_proc_douintvec_minmax_conv, ¶m); 955f461d2dcSChristoph Hellwig } 956f461d2dcSChristoph Hellwig 957cb944413SEric Dumazet /** 958cb944413SEric Dumazet * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values 959cb944413SEric Dumazet * @table: the sysctl table 960cb944413SEric Dumazet * @write: %TRUE if this is a write to the sysctl file 961cb944413SEric Dumazet * @buffer: the user buffer 962cb944413SEric Dumazet * @lenp: the size of the user buffer 963cb944413SEric Dumazet * @ppos: file position 964cb944413SEric Dumazet * 965cb944413SEric Dumazet * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars 966cb944413SEric Dumazet * values from/to the user buffer, treated as an ASCII string. Negative 967cb944413SEric Dumazet * strings are not allowed. 968cb944413SEric Dumazet * 969cb944413SEric Dumazet * This routine will ensure the values are within the range specified by 970cb944413SEric Dumazet * table->extra1 (min) and table->extra2 (max). 971cb944413SEric Dumazet * 972cb944413SEric Dumazet * Returns 0 on success or an error on write when the range check fails. 973cb944413SEric Dumazet */ 974cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write, 975cb944413SEric Dumazet void *buffer, size_t *lenp, loff_t *ppos) 976cb944413SEric Dumazet { 977cb944413SEric Dumazet struct ctl_table tmp; 978cb944413SEric Dumazet unsigned int min = 0, max = 255U, val; 979cb944413SEric Dumazet u8 *data = table->data; 980cb944413SEric Dumazet struct do_proc_douintvec_minmax_conv_param param = { 981cb944413SEric Dumazet .min = &min, 982cb944413SEric Dumazet .max = &max, 983cb944413SEric Dumazet }; 984cb944413SEric Dumazet int res; 985cb944413SEric Dumazet 986cb944413SEric Dumazet /* Do not support arrays yet. */ 987cb944413SEric Dumazet if (table->maxlen != sizeof(u8)) 988cb944413SEric Dumazet return -EINVAL; 989cb944413SEric Dumazet 990cb944413SEric Dumazet if (table->extra1) { 991cb944413SEric Dumazet min = *(unsigned int *) table->extra1; 992cb944413SEric Dumazet if (min > 255U) 993cb944413SEric Dumazet return -EINVAL; 994cb944413SEric Dumazet } 995cb944413SEric Dumazet if (table->extra2) { 996cb944413SEric Dumazet max = *(unsigned int *) table->extra2; 997cb944413SEric Dumazet if (max > 255U) 998cb944413SEric Dumazet return -EINVAL; 999cb944413SEric Dumazet } 1000cb944413SEric Dumazet 1001cb944413SEric Dumazet tmp = *table; 1002cb944413SEric Dumazet 1003cb944413SEric Dumazet tmp.maxlen = sizeof(val); 1004cb944413SEric Dumazet tmp.data = &val; 10057dee5d77SKuniyuki Iwashima val = READ_ONCE(*data); 1006cb944413SEric Dumazet res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos, 1007cb944413SEric Dumazet do_proc_douintvec_minmax_conv, ¶m); 1008cb944413SEric Dumazet if (res) 1009cb944413SEric Dumazet return res; 1010cb944413SEric Dumazet if (write) 10117dee5d77SKuniyuki Iwashima WRITE_ONCE(*data, val); 1012cb944413SEric Dumazet return 0; 1013cb944413SEric Dumazet } 1014cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); 1015cb944413SEric Dumazet 1016f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ 1017f461d2dcSChristoph Hellwig static int sysrq_sysctl_handler(struct ctl_table *table, int write, 101832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1019f461d2dcSChristoph Hellwig { 1020f461d2dcSChristoph Hellwig int tmp, ret; 1021f461d2dcSChristoph Hellwig 1022f461d2dcSChristoph Hellwig tmp = sysrq_mask(); 1023f461d2dcSChristoph Hellwig 1024f461d2dcSChristoph Hellwig ret = __do_proc_dointvec(&tmp, table, write, buffer, 1025f461d2dcSChristoph Hellwig lenp, ppos, NULL, NULL); 1026f461d2dcSChristoph Hellwig if (ret || !write) 1027f461d2dcSChristoph Hellwig return ret; 1028f461d2dcSChristoph Hellwig 1029f461d2dcSChristoph Hellwig if (write) 1030f461d2dcSChristoph Hellwig sysrq_toggle_support(tmp); 1031f461d2dcSChristoph Hellwig 1032f461d2dcSChristoph Hellwig return 0; 1033f461d2dcSChristoph Hellwig } 1034f461d2dcSChristoph Hellwig #endif 1035f461d2dcSChristoph Hellwig 103632927393SChristoph Hellwig static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, 103732927393SChristoph Hellwig int write, void *buffer, size_t *lenp, loff_t *ppos, 103832927393SChristoph Hellwig unsigned long convmul, unsigned long convdiv) 1039f461d2dcSChristoph Hellwig { 1040f461d2dcSChristoph Hellwig unsigned long *i, *min, *max; 1041f461d2dcSChristoph Hellwig int vleft, first = 1, err = 0; 1042f461d2dcSChristoph Hellwig size_t left; 104332927393SChristoph Hellwig char *p; 1044f461d2dcSChristoph Hellwig 1045f461d2dcSChristoph Hellwig if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { 1046f461d2dcSChristoph Hellwig *lenp = 0; 1047f461d2dcSChristoph Hellwig return 0; 1048f461d2dcSChristoph Hellwig } 1049f461d2dcSChristoph Hellwig 10508ebc4123SDong Chuanjian i = data; 10518ebc4123SDong Chuanjian min = table->extra1; 10528ebc4123SDong Chuanjian max = table->extra2; 1053f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(unsigned long); 1054f461d2dcSChristoph Hellwig left = *lenp; 1055f461d2dcSChristoph Hellwig 1056f461d2dcSChristoph Hellwig if (write) { 1057f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table)) 1058f461d2dcSChristoph Hellwig goto out; 1059f461d2dcSChristoph Hellwig 1060f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) 1061f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 106232927393SChristoph Hellwig p = buffer; 1063f461d2dcSChristoph Hellwig } 1064f461d2dcSChristoph Hellwig 1065f461d2dcSChristoph Hellwig for (; left && vleft--; i++, first = 0) { 1066f461d2dcSChristoph Hellwig unsigned long val; 1067f461d2dcSChristoph Hellwig 1068f461d2dcSChristoph Hellwig if (write) { 1069f461d2dcSChristoph Hellwig bool neg; 1070f461d2dcSChristoph Hellwig 1071f461d2dcSChristoph Hellwig left -= proc_skip_spaces(&p); 1072f461d2dcSChristoph Hellwig if (!left) 1073f461d2dcSChristoph Hellwig break; 1074f461d2dcSChristoph Hellwig 1075f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val, &neg, 1076f461d2dcSChristoph Hellwig proc_wspace_sep, 1077f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL); 10781622ed7dSBaokun Li if (err || neg) { 10791622ed7dSBaokun Li err = -EINVAL; 1080f461d2dcSChristoph Hellwig break; 10811622ed7dSBaokun Li } 10821622ed7dSBaokun Li 1083f461d2dcSChristoph Hellwig val = convmul * val / convdiv; 1084f461d2dcSChristoph Hellwig if ((min && val < *min) || (max && val > *max)) { 1085f461d2dcSChristoph Hellwig err = -EINVAL; 1086f461d2dcSChristoph Hellwig break; 1087f461d2dcSChristoph Hellwig } 1088c31bcc8fSKuniyuki Iwashima WRITE_ONCE(*i, val); 1089f461d2dcSChristoph Hellwig } else { 1090c31bcc8fSKuniyuki Iwashima val = convdiv * READ_ONCE(*i) / convmul; 109132927393SChristoph Hellwig if (!first) 109232927393SChristoph Hellwig proc_put_char(&buffer, &left, '\t'); 109332927393SChristoph Hellwig proc_put_long(&buffer, &left, val, false); 1094f461d2dcSChristoph Hellwig } 1095f461d2dcSChristoph Hellwig } 1096f461d2dcSChristoph Hellwig 1097f461d2dcSChristoph Hellwig if (!write && !first && left && !err) 109832927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 1099f461d2dcSChristoph Hellwig if (write && !err) 1100f461d2dcSChristoph Hellwig left -= proc_skip_spaces(&p); 110132927393SChristoph Hellwig if (write && first) 1102f461d2dcSChristoph Hellwig return err ? : -EINVAL; 1103f461d2dcSChristoph Hellwig *lenp -= left; 1104f461d2dcSChristoph Hellwig out: 1105f461d2dcSChristoph Hellwig *ppos += *lenp; 1106f461d2dcSChristoph Hellwig return err; 1107f461d2dcSChristoph Hellwig } 1108f461d2dcSChristoph Hellwig 1109f461d2dcSChristoph Hellwig static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 111032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, 1111f461d2dcSChristoph Hellwig unsigned long convdiv) 1112f461d2dcSChristoph Hellwig { 1113f461d2dcSChristoph Hellwig return __do_proc_doulongvec_minmax(table->data, table, write, 1114f461d2dcSChristoph Hellwig buffer, lenp, ppos, convmul, convdiv); 1115f461d2dcSChristoph Hellwig } 1116f461d2dcSChristoph Hellwig 1117f461d2dcSChristoph Hellwig /** 1118f461d2dcSChristoph Hellwig * proc_doulongvec_minmax - read a vector of long integers with min/max values 1119f461d2dcSChristoph Hellwig * @table: the sysctl table 1120f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1121f461d2dcSChristoph Hellwig * @buffer: the user buffer 1122f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1123f461d2dcSChristoph Hellwig * @ppos: file position 1124f461d2dcSChristoph Hellwig * 1125f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 1126f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1127f461d2dcSChristoph Hellwig * 1128f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 1129f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). 1130f461d2dcSChristoph Hellwig * 1131f461d2dcSChristoph Hellwig * Returns 0 on success. 1132f461d2dcSChristoph Hellwig */ 1133f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write, 113432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1135f461d2dcSChristoph Hellwig { 1136f461d2dcSChristoph Hellwig return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); 1137f461d2dcSChristoph Hellwig } 1138f461d2dcSChristoph Hellwig 1139f461d2dcSChristoph Hellwig /** 1140f461d2dcSChristoph Hellwig * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 1141f461d2dcSChristoph Hellwig * @table: the sysctl table 1142f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1143f461d2dcSChristoph Hellwig * @buffer: the user buffer 1144f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1145f461d2dcSChristoph Hellwig * @ppos: file position 1146f461d2dcSChristoph Hellwig * 1147f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 1148f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. The values 1149f461d2dcSChristoph Hellwig * are treated as milliseconds, and converted to jiffies when they are stored. 1150f461d2dcSChristoph Hellwig * 1151f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 1152f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). 1153f461d2dcSChristoph Hellwig * 1154f461d2dcSChristoph Hellwig * Returns 0 on success. 1155f461d2dcSChristoph Hellwig */ 1156f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 115732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1158f461d2dcSChristoph Hellwig { 1159f461d2dcSChristoph Hellwig return do_proc_doulongvec_minmax(table, write, buffer, 1160f461d2dcSChristoph Hellwig lenp, ppos, HZ, 1000l); 1161f461d2dcSChristoph Hellwig } 1162f461d2dcSChristoph Hellwig 1163f461d2dcSChristoph Hellwig 1164f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, 1165f461d2dcSChristoph Hellwig int *valp, 1166f461d2dcSChristoph Hellwig int write, void *data) 1167f461d2dcSChristoph Hellwig { 1168f461d2dcSChristoph Hellwig if (write) { 1169f461d2dcSChristoph Hellwig if (*lvalp > INT_MAX / HZ) 1170f461d2dcSChristoph Hellwig return 1; 1171e8778208SKuniyuki Iwashima if (*negp) 1172e8778208SKuniyuki Iwashima WRITE_ONCE(*valp, -*lvalp * HZ); 1173e8778208SKuniyuki Iwashima else 1174e8778208SKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp * HZ); 1175f461d2dcSChristoph Hellwig } else { 1176e8778208SKuniyuki Iwashima int val = READ_ONCE(*valp); 1177f461d2dcSChristoph Hellwig unsigned long lval; 1178f461d2dcSChristoph Hellwig if (val < 0) { 1179f461d2dcSChristoph Hellwig *negp = true; 1180f461d2dcSChristoph Hellwig lval = -(unsigned long)val; 1181f461d2dcSChristoph Hellwig } else { 1182f461d2dcSChristoph Hellwig *negp = false; 1183f461d2dcSChristoph Hellwig lval = (unsigned long)val; 1184f461d2dcSChristoph Hellwig } 1185f461d2dcSChristoph Hellwig *lvalp = lval / HZ; 1186f461d2dcSChristoph Hellwig } 1187f461d2dcSChristoph Hellwig return 0; 1188f461d2dcSChristoph Hellwig } 1189f461d2dcSChristoph Hellwig 1190f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, 1191f461d2dcSChristoph Hellwig int *valp, 1192f461d2dcSChristoph Hellwig int write, void *data) 1193f461d2dcSChristoph Hellwig { 1194f461d2dcSChristoph Hellwig if (write) { 1195f461d2dcSChristoph Hellwig if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 1196f461d2dcSChristoph Hellwig return 1; 1197f461d2dcSChristoph Hellwig *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 1198f461d2dcSChristoph Hellwig } else { 1199f461d2dcSChristoph Hellwig int val = *valp; 1200f461d2dcSChristoph Hellwig unsigned long lval; 1201f461d2dcSChristoph Hellwig if (val < 0) { 1202f461d2dcSChristoph Hellwig *negp = true; 1203f461d2dcSChristoph Hellwig lval = -(unsigned long)val; 1204f461d2dcSChristoph Hellwig } else { 1205f461d2dcSChristoph Hellwig *negp = false; 1206f461d2dcSChristoph Hellwig lval = (unsigned long)val; 1207f461d2dcSChristoph Hellwig } 1208f461d2dcSChristoph Hellwig *lvalp = jiffies_to_clock_t(lval); 1209f461d2dcSChristoph Hellwig } 1210f461d2dcSChristoph Hellwig return 0; 1211f461d2dcSChristoph Hellwig } 1212f461d2dcSChristoph Hellwig 1213f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, 1214f461d2dcSChristoph Hellwig int *valp, 1215f461d2dcSChristoph Hellwig int write, void *data) 1216f461d2dcSChristoph Hellwig { 1217f461d2dcSChristoph Hellwig if (write) { 1218f461d2dcSChristoph Hellwig unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 1219f461d2dcSChristoph Hellwig 1220f461d2dcSChristoph Hellwig if (jif > INT_MAX) 1221f461d2dcSChristoph Hellwig return 1; 12227d1025e5SKuniyuki Iwashima WRITE_ONCE(*valp, (int)jif); 1223f461d2dcSChristoph Hellwig } else { 12247d1025e5SKuniyuki Iwashima int val = READ_ONCE(*valp); 1225f461d2dcSChristoph Hellwig unsigned long lval; 1226f461d2dcSChristoph Hellwig if (val < 0) { 1227f461d2dcSChristoph Hellwig *negp = true; 1228f461d2dcSChristoph Hellwig lval = -(unsigned long)val; 1229f461d2dcSChristoph Hellwig } else { 1230f461d2dcSChristoph Hellwig *negp = false; 1231f461d2dcSChristoph Hellwig lval = (unsigned long)val; 1232f461d2dcSChristoph Hellwig } 1233f461d2dcSChristoph Hellwig *lvalp = jiffies_to_msecs(lval); 1234f461d2dcSChristoph Hellwig } 1235f461d2dcSChristoph Hellwig return 0; 1236f461d2dcSChristoph Hellwig } 1237f461d2dcSChristoph Hellwig 1238c381d02bSYuwei Wang static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp, 1239c381d02bSYuwei Wang int *valp, int write, void *data) 1240c381d02bSYuwei Wang { 1241c381d02bSYuwei Wang int tmp, ret; 1242c381d02bSYuwei Wang struct do_proc_dointvec_minmax_conv_param *param = data; 1243c381d02bSYuwei Wang /* 1244c381d02bSYuwei Wang * If writing, first do so via a temporary local int so we can 1245c381d02bSYuwei Wang * bounds-check it before touching *valp. 1246c381d02bSYuwei Wang */ 1247c381d02bSYuwei Wang int *ip = write ? &tmp : valp; 1248c381d02bSYuwei Wang 1249c381d02bSYuwei Wang ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data); 1250c381d02bSYuwei Wang if (ret) 1251c381d02bSYuwei Wang return ret; 1252c381d02bSYuwei Wang 1253c381d02bSYuwei Wang if (write) { 1254c381d02bSYuwei Wang if ((param->min && *param->min > tmp) || 1255c381d02bSYuwei Wang (param->max && *param->max < tmp)) 1256c381d02bSYuwei Wang return -EINVAL; 1257c381d02bSYuwei Wang *valp = tmp; 1258c381d02bSYuwei Wang } 1259c381d02bSYuwei Wang return 0; 1260c381d02bSYuwei Wang } 1261c381d02bSYuwei Wang 1262f461d2dcSChristoph Hellwig /** 1263f461d2dcSChristoph Hellwig * proc_dointvec_jiffies - read a vector of integers as seconds 1264f461d2dcSChristoph Hellwig * @table: the sysctl table 1265f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1266f461d2dcSChristoph Hellwig * @buffer: the user buffer 1267f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1268f461d2dcSChristoph Hellwig * @ppos: file position 1269f461d2dcSChristoph Hellwig * 1270f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1271f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1272f461d2dcSChristoph Hellwig * The values read are assumed to be in seconds, and are converted into 1273f461d2dcSChristoph Hellwig * jiffies. 1274f461d2dcSChristoph Hellwig * 1275f461d2dcSChristoph Hellwig * Returns 0 on success. 1276f461d2dcSChristoph Hellwig */ 1277f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write, 127832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1279f461d2dcSChristoph Hellwig { 1280f461d2dcSChristoph Hellwig return do_proc_dointvec(table,write,buffer,lenp,ppos, 1281f461d2dcSChristoph Hellwig do_proc_dointvec_jiffies_conv,NULL); 1282f461d2dcSChristoph Hellwig } 1283f461d2dcSChristoph Hellwig 1284c381d02bSYuwei Wang int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, 1285c381d02bSYuwei Wang void *buffer, size_t *lenp, loff_t *ppos) 1286c381d02bSYuwei Wang { 1287c381d02bSYuwei Wang struct do_proc_dointvec_minmax_conv_param param = { 1288c381d02bSYuwei Wang .min = (int *) table->extra1, 1289c381d02bSYuwei Wang .max = (int *) table->extra2, 1290c381d02bSYuwei Wang }; 1291c381d02bSYuwei Wang return do_proc_dointvec(table, write, buffer, lenp, ppos, 1292c381d02bSYuwei Wang do_proc_dointvec_ms_jiffies_minmax_conv, ¶m); 1293c381d02bSYuwei Wang } 1294c381d02bSYuwei Wang 1295f461d2dcSChristoph Hellwig /** 1296f461d2dcSChristoph Hellwig * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 1297f461d2dcSChristoph Hellwig * @table: the sysctl table 1298f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1299f461d2dcSChristoph Hellwig * @buffer: the user buffer 1300f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1301f461d2dcSChristoph Hellwig * @ppos: pointer to the file position 1302f461d2dcSChristoph Hellwig * 1303f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1304f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1305f461d2dcSChristoph Hellwig * The values read are assumed to be in 1/USER_HZ seconds, and 1306f461d2dcSChristoph Hellwig * are converted into jiffies. 1307f461d2dcSChristoph Hellwig * 1308f461d2dcSChristoph Hellwig * Returns 0 on success. 1309f461d2dcSChristoph Hellwig */ 1310f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 131132927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1312f461d2dcSChristoph Hellwig { 1313f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, 1314f461d2dcSChristoph Hellwig do_proc_dointvec_userhz_jiffies_conv, NULL); 1315f461d2dcSChristoph Hellwig } 1316f461d2dcSChristoph Hellwig 1317f461d2dcSChristoph Hellwig /** 1318f461d2dcSChristoph Hellwig * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 1319f461d2dcSChristoph Hellwig * @table: the sysctl table 1320f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1321f461d2dcSChristoph Hellwig * @buffer: the user buffer 1322f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1323f461d2dcSChristoph Hellwig * @ppos: file position 1324f461d2dcSChristoph Hellwig * @ppos: the current position in the file 1325f461d2dcSChristoph Hellwig * 1326f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1327f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1328f461d2dcSChristoph Hellwig * The values read are assumed to be in 1/1000 seconds, and 1329f461d2dcSChristoph Hellwig * are converted into jiffies. 1330f461d2dcSChristoph Hellwig * 1331f461d2dcSChristoph Hellwig * Returns 0 on success. 1332f461d2dcSChristoph Hellwig */ 133332927393SChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer, 133432927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 1335f461d2dcSChristoph Hellwig { 1336f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, 1337f461d2dcSChristoph Hellwig do_proc_dointvec_ms_jiffies_conv, NULL); 1338f461d2dcSChristoph Hellwig } 1339f461d2dcSChristoph Hellwig 134032927393SChristoph Hellwig static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, 134132927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 1342f461d2dcSChristoph Hellwig { 1343f461d2dcSChristoph Hellwig struct pid *new_pid; 1344f461d2dcSChristoph Hellwig pid_t tmp; 1345f461d2dcSChristoph Hellwig int r; 1346f461d2dcSChristoph Hellwig 1347f461d2dcSChristoph Hellwig tmp = pid_vnr(cad_pid); 1348f461d2dcSChristoph Hellwig 1349f461d2dcSChristoph Hellwig r = __do_proc_dointvec(&tmp, table, write, buffer, 1350f461d2dcSChristoph Hellwig lenp, ppos, NULL, NULL); 1351f461d2dcSChristoph Hellwig if (r || !write) 1352f461d2dcSChristoph Hellwig return r; 1353f461d2dcSChristoph Hellwig 1354f461d2dcSChristoph Hellwig new_pid = find_get_pid(tmp); 1355f461d2dcSChristoph Hellwig if (!new_pid) 1356f461d2dcSChristoph Hellwig return -ESRCH; 1357f461d2dcSChristoph Hellwig 1358f461d2dcSChristoph Hellwig put_pid(xchg(&cad_pid, new_pid)); 1359f461d2dcSChristoph Hellwig return 0; 1360f461d2dcSChristoph Hellwig } 1361f461d2dcSChristoph Hellwig 1362f461d2dcSChristoph Hellwig /** 1363f461d2dcSChristoph Hellwig * proc_do_large_bitmap - read/write from/to a large bitmap 1364f461d2dcSChristoph Hellwig * @table: the sysctl table 1365f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1366f461d2dcSChristoph Hellwig * @buffer: the user buffer 1367f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1368f461d2dcSChristoph Hellwig * @ppos: file position 1369f461d2dcSChristoph Hellwig * 1370f461d2dcSChristoph Hellwig * The bitmap is stored at table->data and the bitmap length (in bits) 1371f461d2dcSChristoph Hellwig * in table->maxlen. 1372f461d2dcSChristoph Hellwig * 1373f461d2dcSChristoph Hellwig * We use a range comma separated format (e.g. 1,3-4,10-10) so that 1374f461d2dcSChristoph Hellwig * large bitmaps may be represented in a compact manner. Writing into 1375f461d2dcSChristoph Hellwig * the file will clear the bitmap then update it with the given input. 1376f461d2dcSChristoph Hellwig * 1377f461d2dcSChristoph Hellwig * Returns 0 on success. 1378f461d2dcSChristoph Hellwig */ 1379f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write, 138032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1381f461d2dcSChristoph Hellwig { 1382f461d2dcSChristoph Hellwig int err = 0; 1383f461d2dcSChristoph Hellwig size_t left = *lenp; 1384f461d2dcSChristoph Hellwig unsigned long bitmap_len = table->maxlen; 1385f461d2dcSChristoph Hellwig unsigned long *bitmap = *(unsigned long **) table->data; 1386f461d2dcSChristoph Hellwig unsigned long *tmp_bitmap = NULL; 1387f461d2dcSChristoph Hellwig char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; 1388f461d2dcSChristoph Hellwig 1389f461d2dcSChristoph Hellwig if (!bitmap || !bitmap_len || !left || (*ppos && !write)) { 1390f461d2dcSChristoph Hellwig *lenp = 0; 1391f461d2dcSChristoph Hellwig return 0; 1392f461d2dcSChristoph Hellwig } 1393f461d2dcSChristoph Hellwig 1394f461d2dcSChristoph Hellwig if (write) { 139532927393SChristoph Hellwig char *p = buffer; 1396f461d2dcSChristoph Hellwig size_t skipped = 0; 1397f461d2dcSChristoph Hellwig 1398f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) { 1399f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 1400f461d2dcSChristoph Hellwig /* How much of the buffer we'll skip this pass */ 1401f461d2dcSChristoph Hellwig skipped = *lenp - left; 1402f461d2dcSChristoph Hellwig } 1403f461d2dcSChristoph Hellwig 1404f461d2dcSChristoph Hellwig tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL); 140532927393SChristoph Hellwig if (!tmp_bitmap) 1406f461d2dcSChristoph Hellwig return -ENOMEM; 1407f461d2dcSChristoph Hellwig proc_skip_char(&p, &left, '\n'); 1408f461d2dcSChristoph Hellwig while (!err && left) { 1409f461d2dcSChristoph Hellwig unsigned long val_a, val_b; 1410f461d2dcSChristoph Hellwig bool neg; 1411f461d2dcSChristoph Hellwig size_t saved_left; 1412f461d2dcSChristoph Hellwig 1413f461d2dcSChristoph Hellwig /* In case we stop parsing mid-number, we can reset */ 1414f461d2dcSChristoph Hellwig saved_left = left; 1415f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val_a, &neg, tr_a, 1416f461d2dcSChristoph Hellwig sizeof(tr_a), &c); 1417f461d2dcSChristoph Hellwig /* 1418f461d2dcSChristoph Hellwig * If we consumed the entirety of a truncated buffer or 1419f461d2dcSChristoph Hellwig * only one char is left (may be a "-"), then stop here, 1420f461d2dcSChristoph Hellwig * reset, & come back for more. 1421f461d2dcSChristoph Hellwig */ 1422f461d2dcSChristoph Hellwig if ((left <= 1) && skipped) { 1423f461d2dcSChristoph Hellwig left = saved_left; 1424f461d2dcSChristoph Hellwig break; 1425f461d2dcSChristoph Hellwig } 1426f461d2dcSChristoph Hellwig 1427f461d2dcSChristoph Hellwig if (err) 1428f461d2dcSChristoph Hellwig break; 1429f461d2dcSChristoph Hellwig if (val_a >= bitmap_len || neg) { 1430f461d2dcSChristoph Hellwig err = -EINVAL; 1431f461d2dcSChristoph Hellwig break; 1432f461d2dcSChristoph Hellwig } 1433f461d2dcSChristoph Hellwig 1434f461d2dcSChristoph Hellwig val_b = val_a; 1435f461d2dcSChristoph Hellwig if (left) { 1436f461d2dcSChristoph Hellwig p++; 1437f461d2dcSChristoph Hellwig left--; 1438f461d2dcSChristoph Hellwig } 1439f461d2dcSChristoph Hellwig 1440f461d2dcSChristoph Hellwig if (c == '-') { 1441f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val_b, 1442f461d2dcSChristoph Hellwig &neg, tr_b, sizeof(tr_b), 1443f461d2dcSChristoph Hellwig &c); 1444f461d2dcSChristoph Hellwig /* 1445f461d2dcSChristoph Hellwig * If we consumed all of a truncated buffer or 1446f461d2dcSChristoph Hellwig * then stop here, reset, & come back for more. 1447f461d2dcSChristoph Hellwig */ 1448f461d2dcSChristoph Hellwig if (!left && skipped) { 1449f461d2dcSChristoph Hellwig left = saved_left; 1450f461d2dcSChristoph Hellwig break; 1451f461d2dcSChristoph Hellwig } 1452f461d2dcSChristoph Hellwig 1453f461d2dcSChristoph Hellwig if (err) 1454f461d2dcSChristoph Hellwig break; 1455f461d2dcSChristoph Hellwig if (val_b >= bitmap_len || neg || 1456f461d2dcSChristoph Hellwig val_a > val_b) { 1457f461d2dcSChristoph Hellwig err = -EINVAL; 1458f461d2dcSChristoph Hellwig break; 1459f461d2dcSChristoph Hellwig } 1460f461d2dcSChristoph Hellwig if (left) { 1461f461d2dcSChristoph Hellwig p++; 1462f461d2dcSChristoph Hellwig left--; 1463f461d2dcSChristoph Hellwig } 1464f461d2dcSChristoph Hellwig } 1465f461d2dcSChristoph Hellwig 1466f461d2dcSChristoph Hellwig bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); 1467f461d2dcSChristoph Hellwig proc_skip_char(&p, &left, '\n'); 1468f461d2dcSChristoph Hellwig } 1469f461d2dcSChristoph Hellwig left += skipped; 1470f461d2dcSChristoph Hellwig } else { 1471f461d2dcSChristoph Hellwig unsigned long bit_a, bit_b = 0; 14729a52c5f3SJiapeng Chong bool first = 1; 1473f461d2dcSChristoph Hellwig 1474f461d2dcSChristoph Hellwig while (left) { 1475f461d2dcSChristoph Hellwig bit_a = find_next_bit(bitmap, bitmap_len, bit_b); 1476f461d2dcSChristoph Hellwig if (bit_a >= bitmap_len) 1477f461d2dcSChristoph Hellwig break; 1478f461d2dcSChristoph Hellwig bit_b = find_next_zero_bit(bitmap, bitmap_len, 1479f461d2dcSChristoph Hellwig bit_a + 1) - 1; 1480f461d2dcSChristoph Hellwig 148132927393SChristoph Hellwig if (!first) 148232927393SChristoph Hellwig proc_put_char(&buffer, &left, ','); 148332927393SChristoph Hellwig proc_put_long(&buffer, &left, bit_a, false); 1484f461d2dcSChristoph Hellwig if (bit_a != bit_b) { 148532927393SChristoph Hellwig proc_put_char(&buffer, &left, '-'); 148632927393SChristoph Hellwig proc_put_long(&buffer, &left, bit_b, false); 1487f461d2dcSChristoph Hellwig } 1488f461d2dcSChristoph Hellwig 1489f461d2dcSChristoph Hellwig first = 0; bit_b++; 1490f461d2dcSChristoph Hellwig } 149132927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 1492f461d2dcSChristoph Hellwig } 1493f461d2dcSChristoph Hellwig 1494f461d2dcSChristoph Hellwig if (!err) { 1495f461d2dcSChristoph Hellwig if (write) { 1496f461d2dcSChristoph Hellwig if (*ppos) 1497f461d2dcSChristoph Hellwig bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); 1498f461d2dcSChristoph Hellwig else 1499f461d2dcSChristoph Hellwig bitmap_copy(bitmap, tmp_bitmap, bitmap_len); 1500f461d2dcSChristoph Hellwig } 1501f461d2dcSChristoph Hellwig *lenp -= left; 1502f461d2dcSChristoph Hellwig *ppos += *lenp; 1503f461d2dcSChristoph Hellwig } 1504f461d2dcSChristoph Hellwig 1505f461d2dcSChristoph Hellwig bitmap_free(tmp_bitmap); 1506f461d2dcSChristoph Hellwig return err; 1507f461d2dcSChristoph Hellwig } 1508f461d2dcSChristoph Hellwig 1509f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */ 1510f461d2dcSChristoph Hellwig 1511f461d2dcSChristoph Hellwig int proc_dostring(struct ctl_table *table, int write, 151232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1513f461d2dcSChristoph Hellwig { 1514f461d2dcSChristoph Hellwig return -ENOSYS; 1515f461d2dcSChristoph Hellwig } 1516f461d2dcSChristoph Hellwig 1517a2071573SJia He int proc_dobool(struct ctl_table *table, int write, 1518a2071573SJia He void *buffer, size_t *lenp, loff_t *ppos) 1519a2071573SJia He { 1520a2071573SJia He return -ENOSYS; 1521a2071573SJia He } 1522a2071573SJia He 1523f461d2dcSChristoph Hellwig int proc_dointvec(struct ctl_table *table, int write, 152432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1525f461d2dcSChristoph Hellwig { 1526f461d2dcSChristoph Hellwig return -ENOSYS; 1527f461d2dcSChristoph Hellwig } 1528f461d2dcSChristoph Hellwig 1529f461d2dcSChristoph Hellwig int proc_douintvec(struct ctl_table *table, int write, 153032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1531f461d2dcSChristoph Hellwig { 1532f461d2dcSChristoph Hellwig return -ENOSYS; 1533f461d2dcSChristoph Hellwig } 1534f461d2dcSChristoph Hellwig 1535f461d2dcSChristoph Hellwig int proc_dointvec_minmax(struct ctl_table *table, int write, 153632927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1537f461d2dcSChristoph Hellwig { 1538f461d2dcSChristoph Hellwig return -ENOSYS; 1539f461d2dcSChristoph Hellwig } 1540f461d2dcSChristoph Hellwig 1541f461d2dcSChristoph Hellwig int proc_douintvec_minmax(struct ctl_table *table, int write, 154232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1543f461d2dcSChristoph Hellwig { 1544f461d2dcSChristoph Hellwig return -ENOSYS; 1545f461d2dcSChristoph Hellwig } 1546f461d2dcSChristoph Hellwig 1547cb944413SEric Dumazet int proc_dou8vec_minmax(struct ctl_table *table, int write, 1548cb944413SEric Dumazet void *buffer, size_t *lenp, loff_t *ppos) 1549cb944413SEric Dumazet { 1550cb944413SEric Dumazet return -ENOSYS; 1551cb944413SEric Dumazet } 1552cb944413SEric Dumazet 1553f461d2dcSChristoph Hellwig int proc_dointvec_jiffies(struct ctl_table *table, int write, 155432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1555f461d2dcSChristoph Hellwig { 1556f461d2dcSChristoph Hellwig return -ENOSYS; 1557f461d2dcSChristoph Hellwig } 1558f461d2dcSChristoph Hellwig 1559c381d02bSYuwei Wang int proc_dointvec_ms_jiffies_minmax(struct ctl_table *table, int write, 1560c381d02bSYuwei Wang void *buffer, size_t *lenp, loff_t *ppos) 1561c381d02bSYuwei Wang { 1562c381d02bSYuwei Wang return -ENOSYS; 1563c381d02bSYuwei Wang } 1564c381d02bSYuwei Wang 1565f461d2dcSChristoph Hellwig int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 156632927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1567f461d2dcSChristoph Hellwig { 1568f461d2dcSChristoph Hellwig return -ENOSYS; 1569f461d2dcSChristoph Hellwig } 1570f461d2dcSChristoph Hellwig 1571f461d2dcSChristoph Hellwig int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, 157232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1573f461d2dcSChristoph Hellwig { 1574f461d2dcSChristoph Hellwig return -ENOSYS; 1575f461d2dcSChristoph Hellwig } 1576f461d2dcSChristoph Hellwig 1577f461d2dcSChristoph Hellwig int proc_doulongvec_minmax(struct ctl_table *table, int write, 157832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1579f461d2dcSChristoph Hellwig { 1580f461d2dcSChristoph Hellwig return -ENOSYS; 1581f461d2dcSChristoph Hellwig } 1582f461d2dcSChristoph Hellwig 1583f461d2dcSChristoph Hellwig int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 158432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1585f461d2dcSChristoph Hellwig { 1586f461d2dcSChristoph Hellwig return -ENOSYS; 1587f461d2dcSChristoph Hellwig } 1588f461d2dcSChristoph Hellwig 1589f461d2dcSChristoph Hellwig int proc_do_large_bitmap(struct ctl_table *table, int write, 159032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1591f461d2dcSChristoph Hellwig { 1592f461d2dcSChristoph Hellwig return -ENOSYS; 1593f461d2dcSChristoph Hellwig } 1594f461d2dcSChristoph Hellwig 1595f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */ 1596f461d2dcSChristoph Hellwig 1597f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL) 1598f461d2dcSChristoph Hellwig int proc_do_static_key(struct ctl_table *table, int write, 159932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1600f461d2dcSChristoph Hellwig { 1601f461d2dcSChristoph Hellwig struct static_key *key = (struct static_key *)table->data; 1602f461d2dcSChristoph Hellwig static DEFINE_MUTEX(static_key_mutex); 1603f461d2dcSChristoph Hellwig int val, ret; 1604f461d2dcSChristoph Hellwig struct ctl_table tmp = { 1605f461d2dcSChristoph Hellwig .data = &val, 1606f461d2dcSChristoph Hellwig .maxlen = sizeof(val), 1607f461d2dcSChristoph Hellwig .mode = table->mode, 1608f461d2dcSChristoph Hellwig .extra1 = SYSCTL_ZERO, 1609f461d2dcSChristoph Hellwig .extra2 = SYSCTL_ONE, 1610f461d2dcSChristoph Hellwig }; 1611f461d2dcSChristoph Hellwig 1612f461d2dcSChristoph Hellwig if (write && !capable(CAP_SYS_ADMIN)) 1613f461d2dcSChristoph Hellwig return -EPERM; 1614f461d2dcSChristoph Hellwig 1615f461d2dcSChristoph Hellwig mutex_lock(&static_key_mutex); 1616f461d2dcSChristoph Hellwig val = static_key_enabled(key); 1617f461d2dcSChristoph Hellwig ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 1618f461d2dcSChristoph Hellwig if (write && !ret) { 1619f461d2dcSChristoph Hellwig if (val) 1620f461d2dcSChristoph Hellwig static_key_enable(key); 1621f461d2dcSChristoph Hellwig else 1622f461d2dcSChristoph Hellwig static_key_disable(key); 1623f461d2dcSChristoph Hellwig } 1624f461d2dcSChristoph Hellwig mutex_unlock(&static_key_mutex); 1625f461d2dcSChristoph Hellwig return ret; 1626f461d2dcSChristoph Hellwig } 1627f461d2dcSChristoph Hellwig 1628d8217f07SEric W. Biederman static struct ctl_table kern_table[] = { 1629b7cc6ec7SMel Gorman #ifdef CONFIG_NUMA_BALANCING 16303a7053b3SMel Gorman { 163154a43d54SAndi Kleen .procname = "numa_balancing", 163254a43d54SAndi Kleen .data = NULL, /* filled in by handler */ 163354a43d54SAndi Kleen .maxlen = sizeof(unsigned int), 163454a43d54SAndi Kleen .mode = 0644, 163554a43d54SAndi Kleen .proc_handler = sysctl_numa_balancing, 1636eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 1637c574bbe9SHuang Ying .extra2 = SYSCTL_FOUR, 163854a43d54SAndi Kleen }, 1639cbee9f88SPeter Zijlstra #endif /* CONFIG_NUMA_BALANCING */ 16401799e35dSIngo Molnar { 16411da177e4SLinus Torvalds .procname = "panic", 16421da177e4SLinus Torvalds .data = &panic_timeout, 16431da177e4SLinus Torvalds .maxlen = sizeof(int), 16441da177e4SLinus Torvalds .mode = 0644, 16456d456111SEric W. Biederman .proc_handler = proc_dointvec, 16461da177e4SLinus Torvalds }, 164734f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL 16481da177e4SLinus Torvalds { 16491da177e4SLinus Torvalds .procname = "tainted", 165025ddbb18SAndi Kleen .maxlen = sizeof(long), 165134f5a398STheodore Ts'o .mode = 0644, 16526d456111SEric W. Biederman .proc_handler = proc_taint, 16531da177e4SLinus Torvalds }, 1654f4aacea2SKees Cook { 1655f4aacea2SKees Cook .procname = "sysctl_writes_strict", 1656f4aacea2SKees Cook .data = &sysctl_writes_strict, 1657f4aacea2SKees Cook .maxlen = sizeof(int), 1658f4aacea2SKees Cook .mode = 0644, 1659f4aacea2SKees Cook .proc_handler = proc_dointvec_minmax, 166078e36f3bSXiaoming Ni .extra1 = SYSCTL_NEG_ONE, 1661eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 1662f4aacea2SKees Cook }, 166334f5a398STheodore Ts'o #endif 166445807a1dSIngo Molnar { 166545807a1dSIngo Molnar .procname = "print-fatal-signals", 166645807a1dSIngo Molnar .data = &print_fatal_signals, 166745807a1dSIngo Molnar .maxlen = sizeof(int), 166845807a1dSIngo Molnar .mode = 0644, 16696d456111SEric W. Biederman .proc_handler = proc_dointvec, 167045807a1dSIngo Molnar }, 167172c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 16721da177e4SLinus Torvalds { 16731da177e4SLinus Torvalds .procname = "reboot-cmd", 16741da177e4SLinus Torvalds .data = reboot_command, 16751da177e4SLinus Torvalds .maxlen = 256, 16761da177e4SLinus Torvalds .mode = 0644, 16776d456111SEric W. Biederman .proc_handler = proc_dostring, 16781da177e4SLinus Torvalds }, 16791da177e4SLinus Torvalds { 16801da177e4SLinus Torvalds .procname = "stop-a", 16811da177e4SLinus Torvalds .data = &stop_a_enabled, 16821da177e4SLinus Torvalds .maxlen = sizeof (int), 16831da177e4SLinus Torvalds .mode = 0644, 16846d456111SEric W. Biederman .proc_handler = proc_dointvec, 16851da177e4SLinus Torvalds }, 16861da177e4SLinus Torvalds { 16871da177e4SLinus Torvalds .procname = "scons-poweroff", 16881da177e4SLinus Torvalds .data = &scons_pwroff, 16891da177e4SLinus Torvalds .maxlen = sizeof (int), 16901da177e4SLinus Torvalds .mode = 0644, 16916d456111SEric W. Biederman .proc_handler = proc_dointvec, 16921da177e4SLinus Torvalds }, 16931da177e4SLinus Torvalds #endif 16940871420fSDavid S. Miller #ifdef CONFIG_SPARC64 16950871420fSDavid S. Miller { 16960871420fSDavid S. Miller .procname = "tsb-ratio", 16970871420fSDavid S. Miller .data = &sysctl_tsb_ratio, 16980871420fSDavid S. Miller .maxlen = sizeof (int), 16990871420fSDavid S. Miller .mode = 0644, 17006d456111SEric W. Biederman .proc_handler = proc_dointvec, 17010871420fSDavid S. Miller }, 17020871420fSDavid S. Miller #endif 1703b67114dbSHelge Deller #ifdef CONFIG_PARISC 17041da177e4SLinus Torvalds { 17051da177e4SLinus Torvalds .procname = "soft-power", 17061da177e4SLinus Torvalds .data = &pwrsw_enabled, 17071da177e4SLinus Torvalds .maxlen = sizeof (int), 17081da177e4SLinus Torvalds .mode = 0644, 17096d456111SEric W. Biederman .proc_handler = proc_dointvec, 17101da177e4SLinus Torvalds }, 1711bf14e3b9SVineet Gupta #endif 1712bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW 17131da177e4SLinus Torvalds { 17141da177e4SLinus Torvalds .procname = "unaligned-trap", 17151da177e4SLinus Torvalds .data = &unaligned_enabled, 17161da177e4SLinus Torvalds .maxlen = sizeof (int), 17171da177e4SLinus Torvalds .mode = 0644, 17186d456111SEric W. Biederman .proc_handler = proc_dointvec, 17191da177e4SLinus Torvalds }, 17201da177e4SLinus Torvalds #endif 1721f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER 1722f38f1d2aSSteven Rostedt { 1723f38f1d2aSSteven Rostedt .procname = "stack_tracer_enabled", 1724f38f1d2aSSteven Rostedt .data = &stack_tracer_enabled, 1725f38f1d2aSSteven Rostedt .maxlen = sizeof(int), 1726f38f1d2aSSteven Rostedt .mode = 0644, 17276d456111SEric W. Biederman .proc_handler = stack_trace_sysctl, 1728f38f1d2aSSteven Rostedt }, 1729f38f1d2aSSteven Rostedt #endif 1730944ac425SSteven Rostedt #ifdef CONFIG_TRACING 1731944ac425SSteven Rostedt { 17323299b4ddSPeter Zijlstra .procname = "ftrace_dump_on_oops", 1733944ac425SSteven Rostedt .data = &ftrace_dump_on_oops, 1734944ac425SSteven Rostedt .maxlen = sizeof(int), 1735944ac425SSteven Rostedt .mode = 0644, 17366d456111SEric W. Biederman .proc_handler = proc_dointvec, 1737944ac425SSteven Rostedt }, 1738de7edd31SSteven Rostedt (Red Hat) { 1739de7edd31SSteven Rostedt (Red Hat) .procname = "traceoff_on_warning", 1740de7edd31SSteven Rostedt (Red Hat) .data = &__disable_trace_on_warning, 1741de7edd31SSteven Rostedt (Red Hat) .maxlen = sizeof(__disable_trace_on_warning), 1742de7edd31SSteven Rostedt (Red Hat) .mode = 0644, 1743de7edd31SSteven Rostedt (Red Hat) .proc_handler = proc_dointvec, 1744de7edd31SSteven Rostedt (Red Hat) }, 17450daa2302SSteven Rostedt (Red Hat) { 17460daa2302SSteven Rostedt (Red Hat) .procname = "tracepoint_printk", 17470daa2302SSteven Rostedt (Red Hat) .data = &tracepoint_printk, 17480daa2302SSteven Rostedt (Red Hat) .maxlen = sizeof(tracepoint_printk), 17490daa2302SSteven Rostedt (Red Hat) .mode = 0644, 175042391745SSteven Rostedt (Red Hat) .proc_handler = tracepoint_printk_sysctl, 17510daa2302SSteven Rostedt (Red Hat) }, 1752944ac425SSteven Rostedt #endif 1753a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 17541da177e4SLinus Torvalds { 17551da177e4SLinus Torvalds .procname = "modprobe", 17561da177e4SLinus Torvalds .data = &modprobe_path, 17571da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 17581da177e4SLinus Torvalds .mode = 0644, 17596d456111SEric W. Biederman .proc_handler = proc_dostring, 17601da177e4SLinus Torvalds }, 17613d43321bSKees Cook { 17623d43321bSKees Cook .procname = "modules_disabled", 17633d43321bSKees Cook .data = &modules_disabled, 17643d43321bSKees Cook .maxlen = sizeof(int), 17653d43321bSKees Cook .mode = 0644, 17663d43321bSKees Cook /* only handle a transition from default "0" to "1" */ 17676d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1768eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 1769eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 17703d43321bSKees Cook }, 17711da177e4SLinus Torvalds #endif 177286d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER 17731da177e4SLinus Torvalds { 17741da177e4SLinus Torvalds .procname = "hotplug", 1775312c004dSKay Sievers .data = &uevent_helper, 1776312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 17771da177e4SLinus Torvalds .mode = 0644, 17786d456111SEric W. Biederman .proc_handler = proc_dostring, 17791da177e4SLinus Torvalds }, 178086d56134SMichael Marineau #endif 17811da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 17821da177e4SLinus Torvalds { 17831da177e4SLinus Torvalds .procname = "sysrq", 1784eaee4172SDmitry Safonov .data = NULL, 17851da177e4SLinus Torvalds .maxlen = sizeof (int), 17861da177e4SLinus Torvalds .mode = 0644, 178797f5f0cdSDmitry Torokhov .proc_handler = sysrq_sysctl_handler, 17881da177e4SLinus Torvalds }, 17891da177e4SLinus Torvalds #endif 1790d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 17911da177e4SLinus Torvalds { 17921da177e4SLinus Torvalds .procname = "cad_pid", 17939ec52099SCedric Le Goater .data = NULL, 17941da177e4SLinus Torvalds .maxlen = sizeof (int), 17951da177e4SLinus Torvalds .mode = 0600, 17966d456111SEric W. Biederman .proc_handler = proc_do_cad_pid, 17971da177e4SLinus Torvalds }, 1798d6f8ff73SRandy Dunlap #endif 17991da177e4SLinus Torvalds { 18001da177e4SLinus Torvalds .procname = "threads-max", 180116db3d3fSHeinrich Schuchardt .data = NULL, 18021da177e4SLinus Torvalds .maxlen = sizeof(int), 18031da177e4SLinus Torvalds .mode = 0644, 180416db3d3fSHeinrich Schuchardt .proc_handler = sysctl_max_threads, 18051da177e4SLinus Torvalds }, 18061da177e4SLinus Torvalds { 180717f60a7dSEric Paris .procname = "usermodehelper", 180817f60a7dSEric Paris .mode = 0555, 180917f60a7dSEric Paris .child = usermodehelper_table, 181017f60a7dSEric Paris }, 181117f60a7dSEric Paris { 18121da177e4SLinus Torvalds .procname = "overflowuid", 18131da177e4SLinus Torvalds .data = &overflowuid, 18141da177e4SLinus Torvalds .maxlen = sizeof(int), 18151da177e4SLinus Torvalds .mode = 0644, 18166d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 18172452dcb9SXiaoming Ni .extra1 = SYSCTL_ZERO, 181854771613SLuis Chamberlain .extra2 = SYSCTL_MAXOLDUID, 18191da177e4SLinus Torvalds }, 18201da177e4SLinus Torvalds { 18211da177e4SLinus Torvalds .procname = "overflowgid", 18221da177e4SLinus Torvalds .data = &overflowgid, 18231da177e4SLinus Torvalds .maxlen = sizeof(int), 18241da177e4SLinus Torvalds .mode = 0644, 18256d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 18262452dcb9SXiaoming Ni .extra1 = SYSCTL_ZERO, 182754771613SLuis Chamberlain .extra2 = SYSCTL_MAXOLDUID, 18281da177e4SLinus Torvalds }, 1829347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 18301da177e4SLinus Torvalds { 18311da177e4SLinus Torvalds .procname = "userprocess_debug", 1832ab3c68eeSHeiko Carstens .data = &show_unhandled_signals, 18331da177e4SLinus Torvalds .maxlen = sizeof(int), 18341da177e4SLinus Torvalds .mode = 0644, 18356d456111SEric W. Biederman .proc_handler = proc_dointvec, 18361da177e4SLinus Torvalds }, 18371da177e4SLinus Torvalds #endif 18381da177e4SLinus Torvalds { 18391da177e4SLinus Torvalds .procname = "pid_max", 18401da177e4SLinus Torvalds .data = &pid_max, 18411da177e4SLinus Torvalds .maxlen = sizeof (int), 18421da177e4SLinus Torvalds .mode = 0644, 18436d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 18441da177e4SLinus Torvalds .extra1 = &pid_max_min, 18451da177e4SLinus Torvalds .extra2 = &pid_max_max, 18461da177e4SLinus Torvalds }, 18471da177e4SLinus Torvalds { 18481da177e4SLinus Torvalds .procname = "panic_on_oops", 18491da177e4SLinus Torvalds .data = &panic_on_oops, 18501da177e4SLinus Torvalds .maxlen = sizeof(int), 18511da177e4SLinus Torvalds .mode = 0644, 18526d456111SEric W. Biederman .proc_handler = proc_dointvec, 18531da177e4SLinus Torvalds }, 185481c9d43fSFeng Tang { 185581c9d43fSFeng Tang .procname = "panic_print", 185681c9d43fSFeng Tang .data = &panic_print, 185781c9d43fSFeng Tang .maxlen = sizeof(unsigned long), 185881c9d43fSFeng Tang .mode = 0644, 185981c9d43fSFeng Tang .proc_handler = proc_doulongvec_minmax, 186081c9d43fSFeng Tang }, 1861eaf06b24SDan Rosenberg { 18621da177e4SLinus Torvalds .procname = "ngroups_max", 1863f628867dSStephen Kitt .data = (void *)&ngroups_max, 18641da177e4SLinus Torvalds .maxlen = sizeof (int), 18651da177e4SLinus Torvalds .mode = 0444, 18666d456111SEric W. Biederman .proc_handler = proc_dointvec, 18671da177e4SLinus Torvalds }, 186873efc039SDan Ballard { 186973efc039SDan Ballard .procname = "cap_last_cap", 187073efc039SDan Ballard .data = (void *)&cap_last_cap, 187173efc039SDan Ballard .maxlen = sizeof(int), 187273efc039SDan Ballard .mode = 0444, 187373efc039SDan Ballard .proc_handler = proc_dointvec, 187473efc039SDan Ballard }, 18755dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 18765dc30558SDon Zickus { 18775dc30558SDon Zickus .procname = "unknown_nmi_panic", 18785dc30558SDon Zickus .data = &unknown_nmi_panic, 18795dc30558SDon Zickus .maxlen = sizeof (int), 18805dc30558SDon Zickus .mode = 0644, 18815dc30558SDon Zickus .proc_handler = proc_dointvec, 18825dc30558SDon Zickus }, 1883504d7cf1SDon Zickus #endif 1884b6522fa4SXiaoming Ni 1885b6522fa4SXiaoming Ni #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \ 1886b6522fa4SXiaoming Ni defined(CONFIG_DEBUG_STACKOVERFLOW) 1887b6522fa4SXiaoming Ni { 1888b6522fa4SXiaoming Ni .procname = "panic_on_stackoverflow", 1889b6522fa4SXiaoming Ni .data = &sysctl_panic_on_stackoverflow, 1890b6522fa4SXiaoming Ni .maxlen = sizeof(int), 1891b6522fa4SXiaoming Ni .mode = 0644, 1892b6522fa4SXiaoming Ni .proc_handler = proc_dointvec, 1893b6522fa4SXiaoming Ni }, 1894b6522fa4SXiaoming Ni #endif 18951da177e4SLinus Torvalds #if defined(CONFIG_X86) 18961da177e4SLinus Torvalds { 18978da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 18988da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 18998da5addaSDon Zickus .maxlen = sizeof(int), 19008da5addaSDon Zickus .mode = 0644, 19016d456111SEric W. Biederman .proc_handler = proc_dointvec, 19028da5addaSDon Zickus }, 19038da5addaSDon Zickus { 19045211a242SKurt Garloff .procname = "panic_on_io_nmi", 19055211a242SKurt Garloff .data = &panic_on_io_nmi, 19065211a242SKurt Garloff .maxlen = sizeof(int), 19075211a242SKurt Garloff .mode = 0644, 19086d456111SEric W. Biederman .proc_handler = proc_dointvec, 19095211a242SKurt Garloff }, 19105211a242SKurt Garloff { 19111da177e4SLinus Torvalds .procname = "bootloader_type", 19121da177e4SLinus Torvalds .data = &bootloader_type, 19131da177e4SLinus Torvalds .maxlen = sizeof (int), 19141da177e4SLinus Torvalds .mode = 0444, 19156d456111SEric W. Biederman .proc_handler = proc_dointvec, 19161da177e4SLinus Torvalds }, 19170741f4d2SChuck Ebbert { 19185031296cSH. Peter Anvin .procname = "bootloader_version", 19195031296cSH. Peter Anvin .data = &bootloader_version, 19205031296cSH. Peter Anvin .maxlen = sizeof (int), 19215031296cSH. Peter Anvin .mode = 0444, 19226d456111SEric W. Biederman .proc_handler = proc_dointvec, 19235031296cSH. Peter Anvin }, 19245031296cSH. Peter Anvin { 19256e7c4025SIngo Molnar .procname = "io_delay_type", 19266e7c4025SIngo Molnar .data = &io_delay_type, 19276e7c4025SIngo Molnar .maxlen = sizeof(int), 19286e7c4025SIngo Molnar .mode = 0644, 19296d456111SEric W. Biederman .proc_handler = proc_dointvec, 19306e7c4025SIngo Molnar }, 19311da177e4SLinus Torvalds #endif 19327a9166e3SLuke Yang #if defined(CONFIG_MMU) 19331da177e4SLinus Torvalds { 19341da177e4SLinus Torvalds .procname = "randomize_va_space", 19351da177e4SLinus Torvalds .data = &randomize_va_space, 19361da177e4SLinus Torvalds .maxlen = sizeof(int), 19371da177e4SLinus Torvalds .mode = 0644, 19386d456111SEric W. Biederman .proc_handler = proc_dointvec, 19391da177e4SLinus Torvalds }, 19407a9166e3SLuke Yang #endif 19410152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 1942951f22d5SMartin Schwidefsky { 1943951f22d5SMartin Schwidefsky .procname = "spin_retry", 1944951f22d5SMartin Schwidefsky .data = &spin_retry, 1945951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 1946951f22d5SMartin Schwidefsky .mode = 0644, 19476d456111SEric W. Biederman .proc_handler = proc_dointvec, 1948951f22d5SMartin Schwidefsky }, 1949951f22d5SMartin Schwidefsky #endif 1950673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 1951c255d844SPavel Machek { 1952c255d844SPavel Machek .procname = "acpi_video_flags", 195377afcf78SPavel Machek .data = &acpi_realmode_flags, 1954c255d844SPavel Machek .maxlen = sizeof (unsigned long), 1955c255d844SPavel Machek .mode = 0644, 19566d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 1957c255d844SPavel Machek }, 1958c255d844SPavel Machek #endif 1959b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN 1960d2b176edSJes Sorensen { 1961d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 1962d2b176edSJes Sorensen .data = &no_unaligned_warning, 1963d2b176edSJes Sorensen .maxlen = sizeof (int), 1964d2b176edSJes Sorensen .mode = 0644, 19656d456111SEric W. Biederman .proc_handler = proc_dointvec, 1966d2b176edSJes Sorensen }, 1967b6fca725SVineet Gupta #endif 1968b6fca725SVineet Gupta #ifdef CONFIG_IA64 196988fc241fSDoug Chapman { 197088fc241fSDoug Chapman .procname = "unaligned-dump-stack", 197188fc241fSDoug Chapman .data = &unaligned_dump_stack, 197288fc241fSDoug Chapman .maxlen = sizeof (int), 197388fc241fSDoug Chapman .mode = 0644, 19746d456111SEric W. Biederman .proc_handler = proc_dointvec, 197588fc241fSDoug Chapman }, 1976d2b176edSJes Sorensen #endif 197723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 197823f78d4aSIngo Molnar { 197923f78d4aSIngo Molnar .procname = "max_lock_depth", 198023f78d4aSIngo Molnar .data = &max_lock_depth, 198123f78d4aSIngo Molnar .maxlen = sizeof(int), 198223f78d4aSIngo Molnar .mode = 0644, 19836d456111SEric W. Biederman .proc_handler = proc_dointvec, 198423f78d4aSIngo Molnar }, 198523f78d4aSIngo Molnar #endif 19860b77f5bfSDavid Howells #ifdef CONFIG_KEYS 19870b77f5bfSDavid Howells { 19880b77f5bfSDavid Howells .procname = "keys", 19890b77f5bfSDavid Howells .mode = 0555, 19900b77f5bfSDavid Howells .child = key_sysctls, 19910b77f5bfSDavid Howells }, 19920b77f5bfSDavid Howells #endif 1993cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 1994aa4a2218SVince Weaver /* 1995aa4a2218SVince Weaver * User-space scripts rely on the existence of this file 1996aa4a2218SVince Weaver * as a feature check for perf_events being enabled. 1997aa4a2218SVince Weaver * 1998aa4a2218SVince Weaver * So it's an ABI, do not remove! 1999aa4a2218SVince Weaver */ 20001ccd1549SPeter Zijlstra { 2001cdd6c482SIngo Molnar .procname = "perf_event_paranoid", 2002cdd6c482SIngo Molnar .data = &sysctl_perf_event_paranoid, 2003cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_paranoid), 20041ccd1549SPeter Zijlstra .mode = 0644, 20056d456111SEric W. Biederman .proc_handler = proc_dointvec, 20061ccd1549SPeter Zijlstra }, 2007c5078f78SPeter Zijlstra { 2008cdd6c482SIngo Molnar .procname = "perf_event_mlock_kb", 2009cdd6c482SIngo Molnar .data = &sysctl_perf_event_mlock, 2010cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_mlock), 2011c5078f78SPeter Zijlstra .mode = 0644, 20126d456111SEric W. Biederman .proc_handler = proc_dointvec, 2013c5078f78SPeter Zijlstra }, 2014a78ac325SPeter Zijlstra { 2015cdd6c482SIngo Molnar .procname = "perf_event_max_sample_rate", 2016cdd6c482SIngo Molnar .data = &sysctl_perf_event_sample_rate, 2017cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_sample_rate), 2018a78ac325SPeter Zijlstra .mode = 0644, 2019163ec435SPeter Zijlstra .proc_handler = perf_proc_update_handler, 2020eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 2021a78ac325SPeter Zijlstra }, 202214c63f17SDave Hansen { 202314c63f17SDave Hansen .procname = "perf_cpu_time_max_percent", 202414c63f17SDave Hansen .data = &sysctl_perf_cpu_time_max_percent, 202514c63f17SDave Hansen .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), 202614c63f17SDave Hansen .mode = 0644, 202714c63f17SDave Hansen .proc_handler = perf_cpu_time_max_percent_handler, 2028eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 202978e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_HUNDRED, 203014c63f17SDave Hansen }, 2031c5dfd78eSArnaldo Carvalho de Melo { 2032c5dfd78eSArnaldo Carvalho de Melo .procname = "perf_event_max_stack", 2033a831100aSArnaldo Carvalho de Melo .data = &sysctl_perf_event_max_stack, 2034c5dfd78eSArnaldo Carvalho de Melo .maxlen = sizeof(sysctl_perf_event_max_stack), 2035c5dfd78eSArnaldo Carvalho de Melo .mode = 0644, 2036c5dfd78eSArnaldo Carvalho de Melo .proc_handler = perf_event_max_stack_handler, 2037eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2038d73840ecSXiaoming Ni .extra2 = (void *)&six_hundred_forty_kb, 2039c5dfd78eSArnaldo Carvalho de Melo }, 2040c85b0334SArnaldo Carvalho de Melo { 2041c85b0334SArnaldo Carvalho de Melo .procname = "perf_event_max_contexts_per_stack", 2042c85b0334SArnaldo Carvalho de Melo .data = &sysctl_perf_event_max_contexts_per_stack, 2043c85b0334SArnaldo Carvalho de Melo .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), 2044c85b0334SArnaldo Carvalho de Melo .mode = 0644, 2045c85b0334SArnaldo Carvalho de Melo .proc_handler = perf_event_max_stack_handler, 2046eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 204778e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_THOUSAND, 2048c85b0334SArnaldo Carvalho de Melo }, 20491ccd1549SPeter Zijlstra #endif 20509e3961a0SPrarit Bhargava { 20519e3961a0SPrarit Bhargava .procname = "panic_on_warn", 20529e3961a0SPrarit Bhargava .data = &panic_on_warn, 20539e3961a0SPrarit Bhargava .maxlen = sizeof(int), 20549e3961a0SPrarit Bhargava .mode = 0644, 20559e3961a0SPrarit Bhargava .proc_handler = proc_dointvec_minmax, 2056eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2057eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 20589e3961a0SPrarit Bhargava }, 20597251ceb5SGeert Uytterhoeven #ifdef CONFIG_TREE_RCU 2060088e9d25SDaniel Bristot de Oliveira { 2061088e9d25SDaniel Bristot de Oliveira .procname = "panic_on_rcu_stall", 2062088e9d25SDaniel Bristot de Oliveira .data = &sysctl_panic_on_rcu_stall, 2063088e9d25SDaniel Bristot de Oliveira .maxlen = sizeof(sysctl_panic_on_rcu_stall), 2064088e9d25SDaniel Bristot de Oliveira .mode = 0644, 2065088e9d25SDaniel Bristot de Oliveira .proc_handler = proc_dointvec_minmax, 2066eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2067eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 2068088e9d25SDaniel Bristot de Oliveira }, 2069dfe56404Schao { 2070dfe56404Schao .procname = "max_rcu_stall_to_panic", 2071dfe56404Schao .data = &sysctl_max_rcu_stall_to_panic, 2072dfe56404Schao .maxlen = sizeof(sysctl_max_rcu_stall_to_panic), 2073dfe56404Schao .mode = 0644, 2074dfe56404Schao .proc_handler = proc_dointvec_minmax, 2075dfe56404Schao .extra1 = SYSCTL_ONE, 2076dfe56404Schao .extra2 = SYSCTL_INT_MAX, 2077dfe56404Schao }, 2078dfe56404Schao #endif 20796fce56ecSEric W. Biederman { } 20801da177e4SLinus Torvalds }; 20811da177e4SLinus Torvalds 2082d8217f07SEric W. Biederman static struct ctl_table vm_table[] = { 20831da177e4SLinus Torvalds { 20841da177e4SLinus Torvalds .procname = "overcommit_memory", 20851da177e4SLinus Torvalds .data = &sysctl_overcommit_memory, 20861da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_memory), 20871da177e4SLinus Torvalds .mode = 0644, 208856f3547bSFeng Tang .proc_handler = overcommit_policy_handler, 2089eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 209078e36f3bSXiaoming Ni .extra2 = SYSCTL_TWO, 20911da177e4SLinus Torvalds }, 20921da177e4SLinus Torvalds { 20931da177e4SLinus Torvalds .procname = "overcommit_ratio", 20941da177e4SLinus Torvalds .data = &sysctl_overcommit_ratio, 20951da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio), 20961da177e4SLinus Torvalds .mode = 0644, 209749f0ce5fSJerome Marchand .proc_handler = overcommit_ratio_handler, 209849f0ce5fSJerome Marchand }, 209949f0ce5fSJerome Marchand { 210049f0ce5fSJerome Marchand .procname = "overcommit_kbytes", 210149f0ce5fSJerome Marchand .data = &sysctl_overcommit_kbytes, 210249f0ce5fSJerome Marchand .maxlen = sizeof(sysctl_overcommit_kbytes), 210349f0ce5fSJerome Marchand .mode = 0644, 210449f0ce5fSJerome Marchand .proc_handler = overcommit_kbytes_handler, 21051da177e4SLinus Torvalds }, 21061da177e4SLinus Torvalds { 21071da177e4SLinus Torvalds .procname = "page-cluster", 21081da177e4SLinus Torvalds .data = &page_cluster, 21091da177e4SLinus Torvalds .maxlen = sizeof(int), 21101da177e4SLinus Torvalds .mode = 0644, 2111cb16e95fSPetr Holasek .proc_handler = proc_dointvec_minmax, 2112eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 21131da177e4SLinus Torvalds }, 21141da177e4SLinus Torvalds { 21151efff914STheodore Ts'o .procname = "dirtytime_expire_seconds", 21161efff914STheodore Ts'o .data = &dirtytime_expire_interval, 21172d87b309SRandy Dunlap .maxlen = sizeof(dirtytime_expire_interval), 21181efff914STheodore Ts'o .mode = 0644, 21191efff914STheodore Ts'o .proc_handler = dirtytime_interval_handler, 2120eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 21211efff914STheodore Ts'o }, 21221efff914STheodore Ts'o { 21231da177e4SLinus Torvalds .procname = "swappiness", 21241da177e4SLinus Torvalds .data = &vm_swappiness, 21251da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness), 21261da177e4SLinus Torvalds .mode = 0644, 21276d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2128eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 212978e36f3bSXiaoming Ni .extra2 = SYSCTL_TWO_HUNDRED, 21301da177e4SLinus Torvalds }, 213143b5240cSMuchun Song #ifdef CONFIG_NUMA 213243b5240cSMuchun Song { 213343b5240cSMuchun Song .procname = "numa_stat", 213443b5240cSMuchun Song .data = &sysctl_vm_numa_stat, 213543b5240cSMuchun Song .maxlen = sizeof(int), 213643b5240cSMuchun Song .mode = 0644, 213743b5240cSMuchun Song .proc_handler = sysctl_vm_numa_stat_handler, 213843b5240cSMuchun Song .extra1 = SYSCTL_ZERO, 213943b5240cSMuchun Song .extra2 = SYSCTL_ONE, 214043b5240cSMuchun Song }, 214143b5240cSMuchun Song #endif 21421da177e4SLinus Torvalds #ifdef CONFIG_HUGETLB_PAGE 21431da177e4SLinus Torvalds { 21441da177e4SLinus Torvalds .procname = "nr_hugepages", 2145e5ff2159SAndi Kleen .data = NULL, 21461da177e4SLinus Torvalds .maxlen = sizeof(unsigned long), 21471da177e4SLinus Torvalds .mode = 0644, 21486d456111SEric W. Biederman .proc_handler = hugetlb_sysctl_handler, 21491da177e4SLinus Torvalds }, 215006808b08SLee Schermerhorn #ifdef CONFIG_NUMA 215106808b08SLee Schermerhorn { 215206808b08SLee Schermerhorn .procname = "nr_hugepages_mempolicy", 215306808b08SLee Schermerhorn .data = NULL, 215406808b08SLee Schermerhorn .maxlen = sizeof(unsigned long), 215506808b08SLee Schermerhorn .mode = 0644, 215606808b08SLee Schermerhorn .proc_handler = &hugetlb_mempolicy_sysctl_handler, 215706808b08SLee Schermerhorn }, 215806808b08SLee Schermerhorn #endif 21591da177e4SLinus Torvalds { 21601da177e4SLinus Torvalds .procname = "hugetlb_shm_group", 21611da177e4SLinus Torvalds .data = &sysctl_hugetlb_shm_group, 21621da177e4SLinus Torvalds .maxlen = sizeof(gid_t), 21631da177e4SLinus Torvalds .mode = 0644, 21646d456111SEric W. Biederman .proc_handler = proc_dointvec, 21651da177e4SLinus Torvalds }, 2166396faf03SMel Gorman { 2167d1c3fb1fSNishanth Aravamudan .procname = "nr_overcommit_hugepages", 2168e5ff2159SAndi Kleen .data = NULL, 2169e5ff2159SAndi Kleen .maxlen = sizeof(unsigned long), 2170d1c3fb1fSNishanth Aravamudan .mode = 0644, 21716d456111SEric W. Biederman .proc_handler = hugetlb_overcommit_handler, 2172d1c3fb1fSNishanth Aravamudan }, 21731da177e4SLinus Torvalds #endif 21741da177e4SLinus Torvalds { 21751da177e4SLinus Torvalds .procname = "lowmem_reserve_ratio", 21761da177e4SLinus Torvalds .data = &sysctl_lowmem_reserve_ratio, 21771da177e4SLinus Torvalds .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 21781da177e4SLinus Torvalds .mode = 0644, 21796d456111SEric W. Biederman .proc_handler = lowmem_reserve_ratio_sysctl_handler, 21801da177e4SLinus Torvalds }, 21811da177e4SLinus Torvalds { 21829d0243bcSAndrew Morton .procname = "drop_caches", 21839d0243bcSAndrew Morton .data = &sysctl_drop_caches, 21849d0243bcSAndrew Morton .maxlen = sizeof(int), 2185204cb79aSJohannes Weiner .mode = 0200, 21869d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 2187eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 218878e36f3bSXiaoming Ni .extra2 = SYSCTL_FOUR, 21899d0243bcSAndrew Morton }, 219076ab0f53SMel Gorman #ifdef CONFIG_COMPACTION 219176ab0f53SMel Gorman { 219276ab0f53SMel Gorman .procname = "compact_memory", 2193ef498438SPintu Kumar .data = NULL, 219476ab0f53SMel Gorman .maxlen = sizeof(int), 219576ab0f53SMel Gorman .mode = 0200, 219676ab0f53SMel Gorman .proc_handler = sysctl_compaction_handler, 219776ab0f53SMel Gorman }, 21985e771905SMel Gorman { 2199facdaa91SNitin Gupta .procname = "compaction_proactiveness", 2200facdaa91SNitin Gupta .data = &sysctl_compaction_proactiveness, 2201d34c0a75SNitin Gupta .maxlen = sizeof(sysctl_compaction_proactiveness), 2202facdaa91SNitin Gupta .mode = 0644, 220365d759c8SCharan Teja Reddy .proc_handler = compaction_proactiveness_sysctl_handler, 2204facdaa91SNitin Gupta .extra1 = SYSCTL_ZERO, 220578e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_HUNDRED, 2206facdaa91SNitin Gupta }, 2207facdaa91SNitin Gupta { 22085e771905SMel Gorman .procname = "extfrag_threshold", 22095e771905SMel Gorman .data = &sysctl_extfrag_threshold, 22105e771905SMel Gorman .maxlen = sizeof(int), 22115e771905SMel Gorman .mode = 0644, 22126b7e5cadSMatthew Wilcox .proc_handler = proc_dointvec_minmax, 22132452dcb9SXiaoming Ni .extra1 = SYSCTL_ZERO, 2214*feb2bd01SLiu Shixin .extra2 = SYSCTL_ONE_THOUSAND, 22155e771905SMel Gorman }, 22165bbe3547SEric B Munson { 22175bbe3547SEric B Munson .procname = "compact_unevictable_allowed", 22185bbe3547SEric B Munson .data = &sysctl_compact_unevictable_allowed, 22195bbe3547SEric B Munson .maxlen = sizeof(int), 22205bbe3547SEric B Munson .mode = 0644, 22216923aa0dSSebastian Andrzej Siewior .proc_handler = proc_dointvec_minmax_warn_RT_change, 2222eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2223eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 22245bbe3547SEric B Munson }, 22255e771905SMel Gorman 222676ab0f53SMel Gorman #endif /* CONFIG_COMPACTION */ 22279d0243bcSAndrew Morton { 22281da177e4SLinus Torvalds .procname = "min_free_kbytes", 22291da177e4SLinus Torvalds .data = &min_free_kbytes, 22301da177e4SLinus Torvalds .maxlen = sizeof(min_free_kbytes), 22311da177e4SLinus Torvalds .mode = 0644, 22326d456111SEric W. Biederman .proc_handler = min_free_kbytes_sysctl_handler, 2233eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 22341da177e4SLinus Torvalds }, 22358ad4b1fbSRohit Seth { 22361c30844dSMel Gorman .procname = "watermark_boost_factor", 22371c30844dSMel Gorman .data = &watermark_boost_factor, 22381c30844dSMel Gorman .maxlen = sizeof(watermark_boost_factor), 22391c30844dSMel Gorman .mode = 0644, 224026363af5SChristoph Hellwig .proc_handler = proc_dointvec_minmax, 2241eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 22421c30844dSMel Gorman }, 22431c30844dSMel Gorman { 2244795ae7a0SJohannes Weiner .procname = "watermark_scale_factor", 2245795ae7a0SJohannes Weiner .data = &watermark_scale_factor, 2246795ae7a0SJohannes Weiner .maxlen = sizeof(watermark_scale_factor), 2247795ae7a0SJohannes Weiner .mode = 0644, 2248795ae7a0SJohannes Weiner .proc_handler = watermark_scale_factor_sysctl_handler, 2249eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 225078e36f3bSXiaoming Ni .extra2 = SYSCTL_THREE_THOUSAND, 2251795ae7a0SJohannes Weiner }, 2252795ae7a0SJohannes Weiner { 225374f44822SMel Gorman .procname = "percpu_pagelist_high_fraction", 225474f44822SMel Gorman .data = &percpu_pagelist_high_fraction, 225574f44822SMel Gorman .maxlen = sizeof(percpu_pagelist_high_fraction), 22568ad4b1fbSRohit Seth .mode = 0644, 225774f44822SMel Gorman .proc_handler = percpu_pagelist_high_fraction_sysctl_handler, 2258eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 22598ad4b1fbSRohit Seth }, 22605ef64cc8SLinus Torvalds { 22615ef64cc8SLinus Torvalds .procname = "page_lock_unfairness", 22625ef64cc8SLinus Torvalds .data = &sysctl_page_lock_unfairness, 22635ef64cc8SLinus Torvalds .maxlen = sizeof(sysctl_page_lock_unfairness), 22645ef64cc8SLinus Torvalds .mode = 0644, 22655ef64cc8SLinus Torvalds .proc_handler = proc_dointvec_minmax, 22665ef64cc8SLinus Torvalds .extra1 = SYSCTL_ZERO, 22675ef64cc8SLinus Torvalds }, 22681da177e4SLinus Torvalds #ifdef CONFIG_MMU 22691da177e4SLinus Torvalds { 22701da177e4SLinus Torvalds .procname = "max_map_count", 22711da177e4SLinus Torvalds .data = &sysctl_max_map_count, 22721da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 22731da177e4SLinus Torvalds .mode = 0644, 22743e26120cSWANG Cong .proc_handler = proc_dointvec_minmax, 2275eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 22761da177e4SLinus Torvalds }, 2277dd8632a1SPaul Mundt #else 2278dd8632a1SPaul Mundt { 2279dd8632a1SPaul Mundt .procname = "nr_trim_pages", 2280dd8632a1SPaul Mundt .data = &sysctl_nr_trim_pages, 2281dd8632a1SPaul Mundt .maxlen = sizeof(sysctl_nr_trim_pages), 2282dd8632a1SPaul Mundt .mode = 0644, 22836d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2284eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2285dd8632a1SPaul Mundt }, 22861da177e4SLinus Torvalds #endif 22871da177e4SLinus Torvalds { 22881da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 22891da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 22901da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 22911da177e4SLinus Torvalds .mode = 0644, 22923b3376f2SLin Feng .proc_handler = proc_dointvec_minmax, 2293eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 22941da177e4SLinus Torvalds }, 229567f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ 229667f3977fSAlexandre Ghiti defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) 22971da177e4SLinus Torvalds { 22981da177e4SLinus Torvalds .procname = "legacy_va_layout", 22991da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 23001da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 23011da177e4SLinus Torvalds .mode = 0644, 23023b3376f2SLin Feng .proc_handler = proc_dointvec_minmax, 2303eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 23041da177e4SLinus Torvalds }, 23051da177e4SLinus Torvalds #endif 23061743660bSChristoph Lameter #ifdef CONFIG_NUMA 23071743660bSChristoph Lameter { 23081743660bSChristoph Lameter .procname = "zone_reclaim_mode", 2309a5f5f91dSMel Gorman .data = &node_reclaim_mode, 2310a5f5f91dSMel Gorman .maxlen = sizeof(node_reclaim_mode), 23111743660bSChristoph Lameter .mode = 0644, 23123b3376f2SLin Feng .proc_handler = proc_dointvec_minmax, 2313eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 23141743660bSChristoph Lameter }, 23159614634fSChristoph Lameter { 23169614634fSChristoph Lameter .procname = "min_unmapped_ratio", 23179614634fSChristoph Lameter .data = &sysctl_min_unmapped_ratio, 23189614634fSChristoph Lameter .maxlen = sizeof(sysctl_min_unmapped_ratio), 23199614634fSChristoph Lameter .mode = 0644, 23206d456111SEric W. Biederman .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, 2321eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 232278e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_HUNDRED, 23239614634fSChristoph Lameter }, 23240ff38490SChristoph Lameter { 23250ff38490SChristoph Lameter .procname = "min_slab_ratio", 23260ff38490SChristoph Lameter .data = &sysctl_min_slab_ratio, 23270ff38490SChristoph Lameter .maxlen = sizeof(sysctl_min_slab_ratio), 23280ff38490SChristoph Lameter .mode = 0644, 23296d456111SEric W. Biederman .proc_handler = sysctl_min_slab_ratio_sysctl_handler, 2330eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 233178e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_HUNDRED, 23320ff38490SChristoph Lameter }, 23331743660bSChristoph Lameter #endif 233477461ab3SChristoph Lameter #ifdef CONFIG_SMP 233577461ab3SChristoph Lameter { 233677461ab3SChristoph Lameter .procname = "stat_interval", 233777461ab3SChristoph Lameter .data = &sysctl_stat_interval, 233877461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 233977461ab3SChristoph Lameter .mode = 0644, 23406d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 234177461ab3SChristoph Lameter }, 234252b6f46bSHugh Dickins { 234352b6f46bSHugh Dickins .procname = "stat_refresh", 234452b6f46bSHugh Dickins .data = NULL, 234552b6f46bSHugh Dickins .maxlen = 0, 234652b6f46bSHugh Dickins .mode = 0600, 234752b6f46bSHugh Dickins .proc_handler = vmstat_refresh, 234852b6f46bSHugh Dickins }, 234977461ab3SChristoph Lameter #endif 23506e141546SDavid Howells #ifdef CONFIG_MMU 2351ed032189SEric Paris { 2352ed032189SEric Paris .procname = "mmap_min_addr", 2353788084abSEric Paris .data = &dac_mmap_min_addr, 2354ed032189SEric Paris .maxlen = sizeof(unsigned long), 2355ed032189SEric Paris .mode = 0644, 23566d456111SEric W. Biederman .proc_handler = mmap_min_addr_handler, 2357ed032189SEric Paris }, 23586e141546SDavid Howells #endif 2359f0c0b2b8SKAMEZAWA Hiroyuki #ifdef CONFIG_NUMA 2360f0c0b2b8SKAMEZAWA Hiroyuki { 2361f0c0b2b8SKAMEZAWA Hiroyuki .procname = "numa_zonelist_order", 2362f0c0b2b8SKAMEZAWA Hiroyuki .data = &numa_zonelist_order, 2363f0c0b2b8SKAMEZAWA Hiroyuki .maxlen = NUMA_ZONELIST_ORDER_LEN, 2364f0c0b2b8SKAMEZAWA Hiroyuki .mode = 0644, 23656d456111SEric W. Biederman .proc_handler = numa_zonelist_order_handler, 2366f0c0b2b8SKAMEZAWA Hiroyuki }, 2367f0c0b2b8SKAMEZAWA Hiroyuki #endif 23682b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 23695c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 2370e6e5494cSIngo Molnar { 2371e6e5494cSIngo Molnar .procname = "vdso_enabled", 23723d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32 23733d7ee969SAndy Lutomirski .data = &vdso32_enabled, 23743d7ee969SAndy Lutomirski .maxlen = sizeof(vdso32_enabled), 23753d7ee969SAndy Lutomirski #else 2376e6e5494cSIngo Molnar .data = &vdso_enabled, 2377e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 23783d7ee969SAndy Lutomirski #endif 2379e6e5494cSIngo Molnar .mode = 0644, 23806d456111SEric W. Biederman .proc_handler = proc_dointvec, 2381eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2382e6e5494cSIngo Molnar }, 2383e6e5494cSIngo Molnar #endif 23846a46079cSAndi Kleen #ifdef CONFIG_MEMORY_FAILURE 23856a46079cSAndi Kleen { 23866a46079cSAndi Kleen .procname = "memory_failure_early_kill", 23876a46079cSAndi Kleen .data = &sysctl_memory_failure_early_kill, 23886a46079cSAndi Kleen .maxlen = sizeof(sysctl_memory_failure_early_kill), 23896a46079cSAndi Kleen .mode = 0644, 23906d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2391eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2392eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 23936a46079cSAndi Kleen }, 23946a46079cSAndi Kleen { 23956a46079cSAndi Kleen .procname = "memory_failure_recovery", 23966a46079cSAndi Kleen .data = &sysctl_memory_failure_recovery, 23976a46079cSAndi Kleen .maxlen = sizeof(sysctl_memory_failure_recovery), 23986a46079cSAndi Kleen .mode = 0644, 23996d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2400eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2401eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 24026a46079cSAndi Kleen }, 24036a46079cSAndi Kleen #endif 2404c9b1d098SAndrew Shewmaker { 2405c9b1d098SAndrew Shewmaker .procname = "user_reserve_kbytes", 2406c9b1d098SAndrew Shewmaker .data = &sysctl_user_reserve_kbytes, 2407c9b1d098SAndrew Shewmaker .maxlen = sizeof(sysctl_user_reserve_kbytes), 2408c9b1d098SAndrew Shewmaker .mode = 0644, 2409c9b1d098SAndrew Shewmaker .proc_handler = proc_doulongvec_minmax, 2410c9b1d098SAndrew Shewmaker }, 24114eeab4f5SAndrew Shewmaker { 24124eeab4f5SAndrew Shewmaker .procname = "admin_reserve_kbytes", 24134eeab4f5SAndrew Shewmaker .data = &sysctl_admin_reserve_kbytes, 24144eeab4f5SAndrew Shewmaker .maxlen = sizeof(sysctl_admin_reserve_kbytes), 24154eeab4f5SAndrew Shewmaker .mode = 0644, 24164eeab4f5SAndrew Shewmaker .proc_handler = proc_doulongvec_minmax, 24174eeab4f5SAndrew Shewmaker }, 2418d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS 2419d07e2259SDaniel Cashman { 2420d07e2259SDaniel Cashman .procname = "mmap_rnd_bits", 2421d07e2259SDaniel Cashman .data = &mmap_rnd_bits, 2422d07e2259SDaniel Cashman .maxlen = sizeof(mmap_rnd_bits), 2423d07e2259SDaniel Cashman .mode = 0600, 2424d07e2259SDaniel Cashman .proc_handler = proc_dointvec_minmax, 2425d07e2259SDaniel Cashman .extra1 = (void *)&mmap_rnd_bits_min, 2426d07e2259SDaniel Cashman .extra2 = (void *)&mmap_rnd_bits_max, 2427d07e2259SDaniel Cashman }, 2428d07e2259SDaniel Cashman #endif 2429d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS 2430d07e2259SDaniel Cashman { 2431d07e2259SDaniel Cashman .procname = "mmap_rnd_compat_bits", 2432d07e2259SDaniel Cashman .data = &mmap_rnd_compat_bits, 2433d07e2259SDaniel Cashman .maxlen = sizeof(mmap_rnd_compat_bits), 2434d07e2259SDaniel Cashman .mode = 0600, 2435d07e2259SDaniel Cashman .proc_handler = proc_dointvec_minmax, 2436d07e2259SDaniel Cashman .extra1 = (void *)&mmap_rnd_compat_bits_min, 2437d07e2259SDaniel Cashman .extra2 = (void *)&mmap_rnd_compat_bits_max, 2438d07e2259SDaniel Cashman }, 2439d07e2259SDaniel Cashman #endif 2440cefdca0aSPeter Xu #ifdef CONFIG_USERFAULTFD 2441cefdca0aSPeter Xu { 2442cefdca0aSPeter Xu .procname = "unprivileged_userfaultfd", 2443cefdca0aSPeter Xu .data = &sysctl_unprivileged_userfaultfd, 2444cefdca0aSPeter Xu .maxlen = sizeof(sysctl_unprivileged_userfaultfd), 2445cefdca0aSPeter Xu .mode = 0644, 2446cefdca0aSPeter Xu .proc_handler = proc_dointvec_minmax, 2447eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2448eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 2449cefdca0aSPeter Xu }, 2450cefdca0aSPeter Xu #endif 24516fce56ecSEric W. Biederman { } 24521da177e4SLinus Torvalds }; 24531da177e4SLinus Torvalds 2454d8217f07SEric W. Biederman static struct ctl_table debug_table[] = { 24557ac57a89SCatalin Marinas #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE 2456abd4f750SMasoud Asgharifard Sharbiani { 2457abd4f750SMasoud Asgharifard Sharbiani .procname = "exception-trace", 2458abd4f750SMasoud Asgharifard Sharbiani .data = &show_unhandled_signals, 2459abd4f750SMasoud Asgharifard Sharbiani .maxlen = sizeof(int), 2460abd4f750SMasoud Asgharifard Sharbiani .mode = 0644, 2461abd4f750SMasoud Asgharifard Sharbiani .proc_handler = proc_dointvec 2462abd4f750SMasoud Asgharifard Sharbiani }, 2463abd4f750SMasoud Asgharifard Sharbiani #endif 24646fce56ecSEric W. Biederman { } 24651da177e4SLinus Torvalds }; 24661da177e4SLinus Torvalds 2467d8217f07SEric W. Biederman static struct ctl_table dev_table[] = { 24686fce56ecSEric W. Biederman { } 24691da177e4SLinus Torvalds }; 24701da177e4SLinus Torvalds 247151cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(kernel, kern_table); 247251cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(vm, vm_table); 247351cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(debug, debug_table); 247451cb8dfcSLuis Chamberlain DECLARE_SYSCTL_BASE(dev, dev_table); 2475f461d2dcSChristoph Hellwig 2476d8c0418aSLuis Chamberlain int __init sysctl_init_bases(void) 2477330d57fbSAl Viro { 247851cb8dfcSLuis Chamberlain register_sysctl_base(kernel); 247951cb8dfcSLuis Chamberlain register_sysctl_base(vm); 248051cb8dfcSLuis Chamberlain register_sysctl_base(debug); 248151cb8dfcSLuis Chamberlain register_sysctl_base(dev); 2482fd4b616bSSteven Rostedt 2483330d57fbSAl Viro return 0; 2484f7e6ced4SAl Viro } 2485b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 24861da177e4SLinus Torvalds /* 24871da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 24881da177e4SLinus Torvalds * exception granted :-) 24891da177e4SLinus Torvalds */ 2490a2071573SJia He EXPORT_SYMBOL(proc_dobool); 24911da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 2492e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec); 24931da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 24941da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 249561d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax); 24961da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 24971da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 24981da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 24991da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 25001da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 25010bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap); 2502