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> 451da177e4SLinus Torvalds #include <linux/hugetlb.h> 461da177e4SLinus Torvalds #include <linux/initrd.h> 470b77f5bfSDavid Howells #include <linux/key.h> 481da177e4SLinus Torvalds #include <linux/times.h> 491da177e4SLinus Torvalds #include <linux/limits.h> 501da177e4SLinus Torvalds #include <linux/dcache.h> 511da177e4SLinus Torvalds #include <linux/syscalls.h> 52c748e134SAdrian Bunk #include <linux/vmstat.h> 53c255d844SPavel Machek #include <linux/nfs_fs.h> 54c255d844SPavel Machek #include <linux/acpi.h> 5510a0a8d4SJeremy Fitzhardinge #include <linux/reboot.h> 56b0fc494fSSteven Rostedt #include <linux/ftrace.h> 57cdd6c482SIngo Molnar #include <linux/perf_event.h> 588e4228e1SDavid Rientjes #include <linux/oom.h> 5917f60a7dSEric Paris #include <linux/kmod.h> 6073efc039SDan Ballard #include <linux/capability.h> 6140401530SAl Viro #include <linux/binfmts.h> 62cf4aebc2SClark Williams #include <linux/sched/sysctl.h> 63d2921684SEric W. Biederman #include <linux/mount.h> 64cefdca0aSPeter Xu #include <linux/userfaultfd_k.h> 652374c09bSChristoph Hellwig #include <linux/pid.h> 661da177e4SLinus Torvalds 677f2923c4SChristian Brauner #include "../lib/kstrtox.h" 687f2923c4SChristian Brauner 697c0f6ba6SLinus Torvalds #include <linux/uaccess.h> 701da177e4SLinus Torvalds #include <asm/processor.h> 711da177e4SLinus Torvalds 7229cbc78bSAndi Kleen #ifdef CONFIG_X86 7329cbc78bSAndi Kleen #include <asm/nmi.h> 740741f4d2SChuck Ebbert #include <asm/stacktrace.h> 756e7c4025SIngo Molnar #include <asm/io.h> 7629cbc78bSAndi Kleen #endif 77d550bbd4SDavid Howells #ifdef CONFIG_SPARC 78d550bbd4SDavid Howells #include <asm/setup.h> 79d550bbd4SDavid Howells #endif 804f0e056fSDave Young #ifdef CONFIG_RT_MUTEXES 814f0e056fSDave Young #include <linux/rtmutex.h> 824f0e056fSDave Young #endif 83504d7cf1SDon Zickus 84b13bc7cbSLiu Shixin /* shared constants to be used in various sysctls */ 85b13bc7cbSLiu Shixin const int sysctl_vals[] = { 0, 1, 2, 3, 4, 100, 200, 1000, 3000, INT_MAX, 65535, -1 }; 86b13bc7cbSLiu Shixin EXPORT_SYMBOL(sysctl_vals); 87b13bc7cbSLiu Shixin 88b13bc7cbSLiu Shixin const unsigned long sysctl_long_vals[] = { 0, 1, LONG_MAX }; 89b13bc7cbSLiu Shixin EXPORT_SYMBOL_GPL(sysctl_long_vals); 90b13bc7cbSLiu Shixin 911da177e4SLinus Torvalds #if defined(CONFIG_SYSCTL) 921da177e4SLinus Torvalds 93c4f3b63fSRavikiran G Thirumalai /* Constants used for minimum and maximum */ 94c4f3b63fSRavikiran G Thirumalai 95c5dfd78eSArnaldo Carvalho de Melo #ifdef CONFIG_PERF_EVENTS 96d73840ecSXiaoming Ni static const int six_hundred_forty_kb = 640 * 1024; 97c5dfd78eSArnaldo Carvalho de Melo #endif 98c4f3b63fSRavikiran G Thirumalai 999e4a5bdaSAndrea Righi 100f628867dSStephen Kitt static const int ngroups_max = NGROUPS_MAX; 10173efc039SDan Ballard static const int cap_last_cap = CAP_LAST_CAP; 1021da177e4SLinus Torvalds 103d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 104f4aacea2SKees Cook 105a19ac337SLuis R. Rodriguez /** 106a19ac337SLuis R. Rodriguez * enum sysctl_writes_mode - supported sysctl write modes 107a19ac337SLuis R. Rodriguez * 108a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value 109a19ac337SLuis R. Rodriguez * to be written, and multiple writes on the same sysctl file descriptor 110a19ac337SLuis R. Rodriguez * will rewrite the sysctl value, regardless of file position. No warning 111a19ac337SLuis R. Rodriguez * is issued when the initial position is not 0. 112a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is 113a19ac337SLuis R. Rodriguez * not 0. 114a19ac337SLuis R. Rodriguez * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at 115a19ac337SLuis R. Rodriguez * file position 0 and the value must be fully contained in the buffer 116a19ac337SLuis R. Rodriguez * sent to the write syscall. If dealing with strings respect the file 117a19ac337SLuis R. Rodriguez * position, but restrict this to the max length of the buffer, anything 11865f50f25SWeitao Hou * passed the max length will be ignored. Multiple writes will append 119a19ac337SLuis R. Rodriguez * to the buffer. 120a19ac337SLuis R. Rodriguez * 121a19ac337SLuis R. Rodriguez * These write modes control how current file position affects the behavior of 122a19ac337SLuis R. Rodriguez * updating sysctl values through the proc interface on each write. 123a19ac337SLuis R. Rodriguez */ 124a19ac337SLuis R. Rodriguez enum sysctl_writes_mode { 125a19ac337SLuis R. Rodriguez SYSCTL_WRITES_LEGACY = -1, 126a19ac337SLuis R. Rodriguez SYSCTL_WRITES_WARN = 0, 127a19ac337SLuis R. Rodriguez SYSCTL_WRITES_STRICT = 1, 128a19ac337SLuis R. Rodriguez }; 129f4aacea2SKees Cook 130a19ac337SLuis R. Rodriguez static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; 131f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */ 132ceb18132SLuis R. Rodriguez 13367f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ 13467f3977fSAlexandre Ghiti defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) 1351da177e4SLinus Torvalds int sysctl_legacy_va_layout; 1361da177e4SLinus Torvalds #endif 1371da177e4SLinus Torvalds 138f461d2dcSChristoph Hellwig #endif /* CONFIG_SYSCTL */ 139f461d2dcSChristoph Hellwig 140f461d2dcSChristoph Hellwig /* 141f461d2dcSChristoph Hellwig * /proc/sys support 142f461d2dcSChristoph Hellwig */ 143f461d2dcSChristoph Hellwig 144f461d2dcSChristoph Hellwig #ifdef CONFIG_PROC_SYSCTL 145f461d2dcSChristoph Hellwig 146f461d2dcSChristoph Hellwig static int _proc_do_string(char *data, int maxlen, int write, 14732927393SChristoph Hellwig char *buffer, size_t *lenp, loff_t *ppos) 148f461d2dcSChristoph Hellwig { 149f461d2dcSChristoph Hellwig size_t len; 15032927393SChristoph Hellwig char c, *p; 151f461d2dcSChristoph Hellwig 152f461d2dcSChristoph Hellwig if (!data || !maxlen || !*lenp) { 153f461d2dcSChristoph Hellwig *lenp = 0; 154f461d2dcSChristoph Hellwig return 0; 155f461d2dcSChristoph Hellwig } 156f461d2dcSChristoph Hellwig 157f461d2dcSChristoph Hellwig if (write) { 158f461d2dcSChristoph Hellwig if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) { 159f461d2dcSChristoph Hellwig /* Only continue writes not past the end of buffer. */ 160f461d2dcSChristoph Hellwig len = strlen(data); 161f461d2dcSChristoph Hellwig if (len > maxlen - 1) 162f461d2dcSChristoph Hellwig len = maxlen - 1; 163f461d2dcSChristoph Hellwig 164f461d2dcSChristoph Hellwig if (*ppos > len) 165f461d2dcSChristoph Hellwig return 0; 166f461d2dcSChristoph Hellwig len = *ppos; 167f461d2dcSChristoph Hellwig } else { 168f461d2dcSChristoph Hellwig /* Start writing from beginning of buffer. */ 169f461d2dcSChristoph Hellwig len = 0; 170f461d2dcSChristoph Hellwig } 171f461d2dcSChristoph Hellwig 172f461d2dcSChristoph Hellwig *ppos += *lenp; 173f461d2dcSChristoph Hellwig p = buffer; 174f461d2dcSChristoph Hellwig while ((p - buffer) < *lenp && len < maxlen - 1) { 17532927393SChristoph Hellwig c = *(p++); 176f461d2dcSChristoph Hellwig if (c == 0 || c == '\n') 177f461d2dcSChristoph Hellwig break; 178f461d2dcSChristoph Hellwig data[len++] = c; 179f461d2dcSChristoph Hellwig } 180f461d2dcSChristoph Hellwig data[len] = 0; 181f461d2dcSChristoph Hellwig } else { 182f461d2dcSChristoph Hellwig len = strlen(data); 183f461d2dcSChristoph Hellwig if (len > maxlen) 184f461d2dcSChristoph Hellwig len = maxlen; 185f461d2dcSChristoph Hellwig 186f461d2dcSChristoph Hellwig if (*ppos > len) { 187f461d2dcSChristoph Hellwig *lenp = 0; 188f461d2dcSChristoph Hellwig return 0; 189f461d2dcSChristoph Hellwig } 190f461d2dcSChristoph Hellwig 191f461d2dcSChristoph Hellwig data += *ppos; 192f461d2dcSChristoph Hellwig len -= *ppos; 193f461d2dcSChristoph Hellwig 194f461d2dcSChristoph Hellwig if (len > *lenp) 195f461d2dcSChristoph Hellwig len = *lenp; 196f461d2dcSChristoph Hellwig if (len) 19732927393SChristoph Hellwig memcpy(buffer, data, len); 198f461d2dcSChristoph Hellwig if (len < *lenp) { 19932927393SChristoph Hellwig buffer[len] = '\n'; 200f461d2dcSChristoph Hellwig len++; 201f461d2dcSChristoph Hellwig } 202f461d2dcSChristoph Hellwig *lenp = len; 203f461d2dcSChristoph Hellwig *ppos += len; 204f461d2dcSChristoph Hellwig } 205f461d2dcSChristoph Hellwig return 0; 206f461d2dcSChristoph Hellwig } 207f461d2dcSChristoph Hellwig 20832fe9152SThomas Weißschuh static void warn_sysctl_write(const struct ctl_table *table) 209f461d2dcSChristoph Hellwig { 210f461d2dcSChristoph Hellwig pr_warn_once("%s wrote to %s when file position was not 0!\n" 211f461d2dcSChristoph Hellwig "This will not be supported in the future. To silence this\n" 212f461d2dcSChristoph Hellwig "warning, set kernel.sysctl_writes_strict = -1\n", 213f461d2dcSChristoph Hellwig current->comm, table->procname); 214f461d2dcSChristoph Hellwig } 215f461d2dcSChristoph Hellwig 216f461d2dcSChristoph Hellwig /** 217f461d2dcSChristoph Hellwig * proc_first_pos_non_zero_ignore - check if first position is allowed 218f461d2dcSChristoph Hellwig * @ppos: file position 219f461d2dcSChristoph Hellwig * @table: the sysctl table 220f461d2dcSChristoph Hellwig * 221f461d2dcSChristoph Hellwig * Returns true if the first position is non-zero and the sysctl_writes_strict 222f461d2dcSChristoph Hellwig * mode indicates this is not allowed for numeric input types. String proc 223f461d2dcSChristoph Hellwig * handlers can ignore the return value. 224f461d2dcSChristoph Hellwig */ 225f461d2dcSChristoph Hellwig static bool proc_first_pos_non_zero_ignore(loff_t *ppos, 22632fe9152SThomas Weißschuh const struct ctl_table *table) 227f461d2dcSChristoph Hellwig { 228f461d2dcSChristoph Hellwig if (!*ppos) 229f461d2dcSChristoph Hellwig return false; 230f461d2dcSChristoph Hellwig 231f461d2dcSChristoph Hellwig switch (sysctl_writes_strict) { 232f461d2dcSChristoph Hellwig case SYSCTL_WRITES_STRICT: 233f461d2dcSChristoph Hellwig return true; 234f461d2dcSChristoph Hellwig case SYSCTL_WRITES_WARN: 235f461d2dcSChristoph Hellwig warn_sysctl_write(table); 236f461d2dcSChristoph Hellwig return false; 237f461d2dcSChristoph Hellwig default: 238f461d2dcSChristoph Hellwig return false; 239f461d2dcSChristoph Hellwig } 240f461d2dcSChristoph Hellwig } 241f461d2dcSChristoph Hellwig 242f461d2dcSChristoph Hellwig /** 243f461d2dcSChristoph Hellwig * proc_dostring - read a string sysctl 244f461d2dcSChristoph Hellwig * @table: the sysctl table 245f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 246f461d2dcSChristoph Hellwig * @buffer: the user buffer 247f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 248f461d2dcSChristoph Hellwig * @ppos: file position 249f461d2dcSChristoph Hellwig * 250f461d2dcSChristoph Hellwig * Reads/writes a string from/to the user buffer. If the kernel 251f461d2dcSChristoph Hellwig * buffer provided is not large enough to hold the string, the 252f461d2dcSChristoph Hellwig * string is truncated. The copied string is %NULL-terminated. 253f461d2dcSChristoph Hellwig * If the string is being read by the user process, it is copied 254f461d2dcSChristoph Hellwig * and a newline '\n' is added. It is truncated if the buffer is 255f461d2dcSChristoph Hellwig * not large enough. 256f461d2dcSChristoph Hellwig * 257f461d2dcSChristoph Hellwig * Returns 0 on success. 258f461d2dcSChristoph Hellwig */ 259*78eb4ea2SJoel Granados int proc_dostring(const struct ctl_table *table, int write, 26032927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 261f461d2dcSChristoph Hellwig { 262f461d2dcSChristoph Hellwig if (write) 263f461d2dcSChristoph Hellwig proc_first_pos_non_zero_ignore(ppos, table); 264f461d2dcSChristoph Hellwig 26532927393SChristoph Hellwig return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, 26632927393SChristoph Hellwig ppos); 267f461d2dcSChristoph Hellwig } 268f461d2dcSChristoph Hellwig 269bce93322SLinus Torvalds static void proc_skip_spaces(char **buf, size_t *size) 270f461d2dcSChristoph Hellwig { 271bce93322SLinus Torvalds while (*size) { 272bce93322SLinus Torvalds if (!isspace(**buf)) 273bce93322SLinus Torvalds break; 274bce93322SLinus Torvalds (*size)--; 275bce93322SLinus Torvalds (*buf)++; 276bce93322SLinus Torvalds } 277f461d2dcSChristoph Hellwig } 278f461d2dcSChristoph Hellwig 279f461d2dcSChristoph Hellwig static void proc_skip_char(char **buf, size_t *size, const char v) 280f461d2dcSChristoph Hellwig { 281f461d2dcSChristoph Hellwig while (*size) { 282f461d2dcSChristoph Hellwig if (**buf != v) 283f461d2dcSChristoph Hellwig break; 284f461d2dcSChristoph Hellwig (*size)--; 285f461d2dcSChristoph Hellwig (*buf)++; 286f461d2dcSChristoph Hellwig } 287f461d2dcSChristoph Hellwig } 288f461d2dcSChristoph Hellwig 289f461d2dcSChristoph Hellwig /** 290f461d2dcSChristoph Hellwig * strtoul_lenient - parse an ASCII formatted integer from a buffer and only 291f461d2dcSChristoph Hellwig * fail on overflow 292f461d2dcSChristoph Hellwig * 293f461d2dcSChristoph Hellwig * @cp: kernel buffer containing the string to parse 294f461d2dcSChristoph Hellwig * @endp: pointer to store the trailing characters 295f461d2dcSChristoph Hellwig * @base: the base to use 296f461d2dcSChristoph Hellwig * @res: where the parsed integer will be stored 297f461d2dcSChristoph Hellwig * 298f461d2dcSChristoph Hellwig * In case of success 0 is returned and @res will contain the parsed integer, 299f461d2dcSChristoph Hellwig * @endp will hold any trailing characters. 300f461d2dcSChristoph Hellwig * This function will fail the parse on overflow. If there wasn't an overflow 301f461d2dcSChristoph Hellwig * the function will defer the decision what characters count as invalid to the 302f461d2dcSChristoph Hellwig * caller. 303f461d2dcSChristoph Hellwig */ 304f461d2dcSChristoph Hellwig static int strtoul_lenient(const char *cp, char **endp, unsigned int base, 305f461d2dcSChristoph Hellwig unsigned long *res) 306f461d2dcSChristoph Hellwig { 307f461d2dcSChristoph Hellwig unsigned long long result; 308f461d2dcSChristoph Hellwig unsigned int rv; 309f461d2dcSChristoph Hellwig 310f461d2dcSChristoph Hellwig cp = _parse_integer_fixup_radix(cp, &base); 311f461d2dcSChristoph Hellwig rv = _parse_integer(cp, base, &result); 312f461d2dcSChristoph Hellwig if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result)) 313f461d2dcSChristoph Hellwig return -ERANGE; 314f461d2dcSChristoph Hellwig 315f461d2dcSChristoph Hellwig cp += rv; 316f461d2dcSChristoph Hellwig 317f461d2dcSChristoph Hellwig if (endp) 318f461d2dcSChristoph Hellwig *endp = (char *)cp; 319f461d2dcSChristoph Hellwig 320f461d2dcSChristoph Hellwig *res = (unsigned long)result; 321f461d2dcSChristoph Hellwig return 0; 322f461d2dcSChristoph Hellwig } 323f461d2dcSChristoph Hellwig 324f461d2dcSChristoph Hellwig #define TMPBUFLEN 22 325f461d2dcSChristoph Hellwig /** 326f461d2dcSChristoph Hellwig * proc_get_long - reads an ASCII formatted integer from a user buffer 327f461d2dcSChristoph Hellwig * 328f461d2dcSChristoph Hellwig * @buf: a kernel buffer 329f461d2dcSChristoph Hellwig * @size: size of the kernel buffer 330f461d2dcSChristoph Hellwig * @val: this is where the number will be stored 331f461d2dcSChristoph Hellwig * @neg: set to %TRUE if number is negative 332f461d2dcSChristoph Hellwig * @perm_tr: a vector which contains the allowed trailers 333f461d2dcSChristoph Hellwig * @perm_tr_len: size of the perm_tr vector 334f461d2dcSChristoph Hellwig * @tr: pointer to store the trailer character 335f461d2dcSChristoph Hellwig * 336f461d2dcSChristoph Hellwig * In case of success %0 is returned and @buf and @size are updated with 337f461d2dcSChristoph Hellwig * the amount of bytes read. If @tr is non-NULL and a trailing 338f461d2dcSChristoph Hellwig * character exists (size is non-zero after returning from this 339f461d2dcSChristoph Hellwig * function), @tr is updated with the trailing character. 340f461d2dcSChristoph Hellwig */ 341f461d2dcSChristoph Hellwig static int proc_get_long(char **buf, size_t *size, 342f461d2dcSChristoph Hellwig unsigned long *val, bool *neg, 343f461d2dcSChristoph Hellwig const char *perm_tr, unsigned perm_tr_len, char *tr) 344f461d2dcSChristoph Hellwig { 345f461d2dcSChristoph Hellwig char *p, tmp[TMPBUFLEN]; 346e6cfaf34SLinus Torvalds ssize_t len = *size; 347f461d2dcSChristoph Hellwig 348e6cfaf34SLinus Torvalds if (len <= 0) 349f461d2dcSChristoph Hellwig return -EINVAL; 350f461d2dcSChristoph Hellwig 351f461d2dcSChristoph Hellwig if (len > TMPBUFLEN - 1) 352f461d2dcSChristoph Hellwig len = TMPBUFLEN - 1; 353f461d2dcSChristoph Hellwig 354f461d2dcSChristoph Hellwig memcpy(tmp, *buf, len); 355f461d2dcSChristoph Hellwig 356f461d2dcSChristoph Hellwig tmp[len] = 0; 357f461d2dcSChristoph Hellwig p = tmp; 358f461d2dcSChristoph Hellwig if (*p == '-' && *size > 1) { 359f461d2dcSChristoph Hellwig *neg = true; 360f461d2dcSChristoph Hellwig p++; 361f461d2dcSChristoph Hellwig } else 362f461d2dcSChristoph Hellwig *neg = false; 363f461d2dcSChristoph Hellwig if (!isdigit(*p)) 364f461d2dcSChristoph Hellwig return -EINVAL; 365f461d2dcSChristoph Hellwig 366f461d2dcSChristoph Hellwig if (strtoul_lenient(p, &p, 0, val)) 367f461d2dcSChristoph Hellwig return -EINVAL; 368f461d2dcSChristoph Hellwig 369f461d2dcSChristoph Hellwig len = p - tmp; 370f461d2dcSChristoph Hellwig 371f461d2dcSChristoph Hellwig /* We don't know if the next char is whitespace thus we may accept 372f461d2dcSChristoph Hellwig * invalid integers (e.g. 1234...a) or two integers instead of one 373f461d2dcSChristoph Hellwig * (e.g. 123...1). So lets not allow such large numbers. */ 374f461d2dcSChristoph Hellwig if (len == TMPBUFLEN - 1) 375f461d2dcSChristoph Hellwig return -EINVAL; 376f461d2dcSChristoph Hellwig 377f461d2dcSChristoph Hellwig if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) 378f461d2dcSChristoph Hellwig return -EINVAL; 379f461d2dcSChristoph Hellwig 380f461d2dcSChristoph Hellwig if (tr && (len < *size)) 381f461d2dcSChristoph Hellwig *tr = *p; 382f461d2dcSChristoph Hellwig 383f461d2dcSChristoph Hellwig *buf += len; 384f461d2dcSChristoph Hellwig *size -= len; 385f461d2dcSChristoph Hellwig 386f461d2dcSChristoph Hellwig return 0; 387f461d2dcSChristoph Hellwig } 388f461d2dcSChristoph Hellwig 389f461d2dcSChristoph Hellwig /** 390f461d2dcSChristoph Hellwig * proc_put_long - converts an integer to a decimal ASCII formatted string 391f461d2dcSChristoph Hellwig * 392f461d2dcSChristoph Hellwig * @buf: the user buffer 393f461d2dcSChristoph Hellwig * @size: the size of the user buffer 394f461d2dcSChristoph Hellwig * @val: the integer to be converted 395f461d2dcSChristoph Hellwig * @neg: sign of the number, %TRUE for negative 396f461d2dcSChristoph Hellwig * 39732927393SChristoph Hellwig * In case of success @buf and @size are updated with the amount of bytes 39832927393SChristoph Hellwig * written. 399f461d2dcSChristoph Hellwig */ 40032927393SChristoph Hellwig static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) 401f461d2dcSChristoph Hellwig { 402f461d2dcSChristoph Hellwig int len; 403f461d2dcSChristoph Hellwig char tmp[TMPBUFLEN], *p = tmp; 404f461d2dcSChristoph Hellwig 405f461d2dcSChristoph Hellwig sprintf(p, "%s%lu", neg ? "-" : "", val); 406f461d2dcSChristoph Hellwig len = strlen(tmp); 407f461d2dcSChristoph Hellwig if (len > *size) 408f461d2dcSChristoph Hellwig len = *size; 40932927393SChristoph Hellwig memcpy(*buf, tmp, len); 410f461d2dcSChristoph Hellwig *size -= len; 411f461d2dcSChristoph Hellwig *buf += len; 412f461d2dcSChristoph Hellwig } 413f461d2dcSChristoph Hellwig #undef TMPBUFLEN 414f461d2dcSChristoph Hellwig 41532927393SChristoph Hellwig static void proc_put_char(void **buf, size_t *size, char c) 416f461d2dcSChristoph Hellwig { 417f461d2dcSChristoph Hellwig if (*size) { 41832927393SChristoph Hellwig char **buffer = (char **)buf; 41932927393SChristoph Hellwig **buffer = c; 42032927393SChristoph Hellwig 42132927393SChristoph Hellwig (*size)--; 42232927393SChristoph Hellwig (*buffer)++; 423f461d2dcSChristoph Hellwig *buf = *buffer; 424f461d2dcSChristoph Hellwig } 425f461d2dcSChristoph Hellwig } 426f461d2dcSChristoph Hellwig 427f461d2dcSChristoph Hellwig static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 428f461d2dcSChristoph Hellwig int *valp, 429f461d2dcSChristoph Hellwig int write, void *data) 430f461d2dcSChristoph Hellwig { 431f461d2dcSChristoph Hellwig if (write) { 432f461d2dcSChristoph Hellwig if (*negp) { 433f461d2dcSChristoph Hellwig if (*lvalp > (unsigned long) INT_MAX + 1) 434f461d2dcSChristoph Hellwig return -EINVAL; 4351f1be04bSKuniyuki Iwashima WRITE_ONCE(*valp, -*lvalp); 436f461d2dcSChristoph Hellwig } else { 437f461d2dcSChristoph Hellwig if (*lvalp > (unsigned long) INT_MAX) 438f461d2dcSChristoph Hellwig return -EINVAL; 4391f1be04bSKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp); 440f461d2dcSChristoph Hellwig } 441f461d2dcSChristoph Hellwig } else { 4421f1be04bSKuniyuki Iwashima int val = READ_ONCE(*valp); 443f461d2dcSChristoph Hellwig if (val < 0) { 444f461d2dcSChristoph Hellwig *negp = true; 445f461d2dcSChristoph Hellwig *lvalp = -(unsigned long)val; 446f461d2dcSChristoph Hellwig } else { 447f461d2dcSChristoph Hellwig *negp = false; 448f461d2dcSChristoph Hellwig *lvalp = (unsigned long)val; 449f461d2dcSChristoph Hellwig } 450f461d2dcSChristoph Hellwig } 451f461d2dcSChristoph Hellwig return 0; 452f461d2dcSChristoph Hellwig } 453f461d2dcSChristoph Hellwig 454f461d2dcSChristoph Hellwig static int do_proc_douintvec_conv(unsigned long *lvalp, 455f461d2dcSChristoph Hellwig unsigned int *valp, 456f461d2dcSChristoph Hellwig int write, void *data) 457f461d2dcSChristoph Hellwig { 458f461d2dcSChristoph Hellwig if (write) { 459f461d2dcSChristoph Hellwig if (*lvalp > UINT_MAX) 460f461d2dcSChristoph Hellwig return -EINVAL; 4614762b532SKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp); 462f461d2dcSChristoph Hellwig } else { 4634762b532SKuniyuki Iwashima unsigned int val = READ_ONCE(*valp); 464f461d2dcSChristoph Hellwig *lvalp = (unsigned long)val; 465f461d2dcSChristoph Hellwig } 466f461d2dcSChristoph Hellwig return 0; 467f461d2dcSChristoph Hellwig } 468f461d2dcSChristoph Hellwig 469f461d2dcSChristoph Hellwig static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; 470f461d2dcSChristoph Hellwig 47132fe9152SThomas Weißschuh static int __do_proc_dointvec(void *tbl_data, const struct ctl_table *table, 47232927393SChristoph Hellwig int write, void *buffer, 473f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 474f461d2dcSChristoph Hellwig int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 475f461d2dcSChristoph Hellwig int write, void *data), 476f461d2dcSChristoph Hellwig void *data) 477f461d2dcSChristoph Hellwig { 478f461d2dcSChristoph Hellwig int *i, vleft, first = 1, err = 0; 479f461d2dcSChristoph Hellwig size_t left; 48032927393SChristoph Hellwig char *p; 481f461d2dcSChristoph Hellwig 482f461d2dcSChristoph Hellwig if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 483f461d2dcSChristoph Hellwig *lenp = 0; 484f461d2dcSChristoph Hellwig return 0; 485f461d2dcSChristoph Hellwig } 486f461d2dcSChristoph Hellwig 487f461d2dcSChristoph Hellwig i = (int *) tbl_data; 488f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(*i); 489f461d2dcSChristoph Hellwig left = *lenp; 490f461d2dcSChristoph Hellwig 491f461d2dcSChristoph Hellwig if (!conv) 492f461d2dcSChristoph Hellwig conv = do_proc_dointvec_conv; 493f461d2dcSChristoph Hellwig 494f461d2dcSChristoph Hellwig if (write) { 495f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table)) 496f461d2dcSChristoph Hellwig goto out; 497f461d2dcSChristoph Hellwig 498f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) 499f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 50032927393SChristoph Hellwig p = buffer; 501f461d2dcSChristoph Hellwig } 502f461d2dcSChristoph Hellwig 503f461d2dcSChristoph Hellwig for (; left && vleft--; i++, first=0) { 504f461d2dcSChristoph Hellwig unsigned long lval; 505f461d2dcSChristoph Hellwig bool neg; 506f461d2dcSChristoph Hellwig 507f461d2dcSChristoph Hellwig if (write) { 508bce93322SLinus Torvalds proc_skip_spaces(&p, &left); 509f461d2dcSChristoph Hellwig 510f461d2dcSChristoph Hellwig if (!left) 511f461d2dcSChristoph Hellwig break; 512f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &lval, &neg, 513f461d2dcSChristoph Hellwig proc_wspace_sep, 514f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL); 515f461d2dcSChristoph Hellwig if (err) 516f461d2dcSChristoph Hellwig break; 517f461d2dcSChristoph Hellwig if (conv(&neg, &lval, i, 1, data)) { 518f461d2dcSChristoph Hellwig err = -EINVAL; 519f461d2dcSChristoph Hellwig break; 520f461d2dcSChristoph Hellwig } 521f461d2dcSChristoph Hellwig } else { 522f461d2dcSChristoph Hellwig if (conv(&neg, &lval, i, 0, data)) { 523f461d2dcSChristoph Hellwig err = -EINVAL; 524f461d2dcSChristoph Hellwig break; 525f461d2dcSChristoph Hellwig } 526f461d2dcSChristoph Hellwig if (!first) 52732927393SChristoph Hellwig proc_put_char(&buffer, &left, '\t'); 52832927393SChristoph Hellwig proc_put_long(&buffer, &left, lval, neg); 529f461d2dcSChristoph Hellwig } 530f461d2dcSChristoph Hellwig } 531f461d2dcSChristoph Hellwig 532f461d2dcSChristoph Hellwig if (!write && !first && left && !err) 53332927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 534f461d2dcSChristoph Hellwig if (write && !err && left) 535bce93322SLinus Torvalds proc_skip_spaces(&p, &left); 53632927393SChristoph Hellwig if (write && first) 537f461d2dcSChristoph Hellwig return err ? : -EINVAL; 538f461d2dcSChristoph Hellwig *lenp -= left; 539f461d2dcSChristoph Hellwig out: 540f461d2dcSChristoph Hellwig *ppos += *lenp; 541f461d2dcSChristoph Hellwig return err; 542f461d2dcSChristoph Hellwig } 543f461d2dcSChristoph Hellwig 54432fe9152SThomas Weißschuh static int do_proc_dointvec(const struct ctl_table *table, int write, 54532927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, 546f461d2dcSChristoph Hellwig int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 547f461d2dcSChristoph Hellwig int write, void *data), 548f461d2dcSChristoph Hellwig void *data) 549f461d2dcSChristoph Hellwig { 550f461d2dcSChristoph Hellwig return __do_proc_dointvec(table->data, table, write, 551f461d2dcSChristoph Hellwig buffer, lenp, ppos, conv, data); 552f461d2dcSChristoph Hellwig } 553f461d2dcSChristoph Hellwig 554f461d2dcSChristoph Hellwig static int do_proc_douintvec_w(unsigned int *tbl_data, 55532fe9152SThomas Weißschuh const struct ctl_table *table, 55632927393SChristoph Hellwig void *buffer, 557f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 558f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 559f461d2dcSChristoph Hellwig unsigned int *valp, 560f461d2dcSChristoph Hellwig int write, void *data), 561f461d2dcSChristoph Hellwig void *data) 562f461d2dcSChristoph Hellwig { 563f461d2dcSChristoph Hellwig unsigned long lval; 564f461d2dcSChristoph Hellwig int err = 0; 565f461d2dcSChristoph Hellwig size_t left; 566f461d2dcSChristoph Hellwig bool neg; 56732927393SChristoph Hellwig char *p = buffer; 568f461d2dcSChristoph Hellwig 569f461d2dcSChristoph Hellwig left = *lenp; 570f461d2dcSChristoph Hellwig 571f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table)) 572f461d2dcSChristoph Hellwig goto bail_early; 573f461d2dcSChristoph Hellwig 574f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) 575f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 576f461d2dcSChristoph Hellwig 577bce93322SLinus Torvalds proc_skip_spaces(&p, &left); 578f461d2dcSChristoph Hellwig if (!left) { 579f461d2dcSChristoph Hellwig err = -EINVAL; 580f461d2dcSChristoph Hellwig goto out_free; 581f461d2dcSChristoph Hellwig } 582f461d2dcSChristoph Hellwig 583f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &lval, &neg, 584f461d2dcSChristoph Hellwig proc_wspace_sep, 585f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL); 586f461d2dcSChristoph Hellwig if (err || neg) { 587f461d2dcSChristoph Hellwig err = -EINVAL; 588f461d2dcSChristoph Hellwig goto out_free; 589f461d2dcSChristoph Hellwig } 590f461d2dcSChristoph Hellwig 591f461d2dcSChristoph Hellwig if (conv(&lval, tbl_data, 1, data)) { 592f461d2dcSChristoph Hellwig err = -EINVAL; 593f461d2dcSChristoph Hellwig goto out_free; 594f461d2dcSChristoph Hellwig } 595f461d2dcSChristoph Hellwig 596f461d2dcSChristoph Hellwig if (!err && left) 597bce93322SLinus Torvalds proc_skip_spaces(&p, &left); 598f461d2dcSChristoph Hellwig 599f461d2dcSChristoph Hellwig out_free: 600f461d2dcSChristoph Hellwig if (err) 601f461d2dcSChristoph Hellwig return -EINVAL; 602f461d2dcSChristoph Hellwig 603f461d2dcSChristoph Hellwig return 0; 604f461d2dcSChristoph Hellwig 605f461d2dcSChristoph Hellwig /* This is in keeping with old __do_proc_dointvec() */ 606f461d2dcSChristoph Hellwig bail_early: 607f461d2dcSChristoph Hellwig *ppos += *lenp; 608f461d2dcSChristoph Hellwig return err; 609f461d2dcSChristoph Hellwig } 610f461d2dcSChristoph Hellwig 61132927393SChristoph Hellwig static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer, 612f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 613f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 614f461d2dcSChristoph Hellwig unsigned int *valp, 615f461d2dcSChristoph Hellwig int write, void *data), 616f461d2dcSChristoph Hellwig void *data) 617f461d2dcSChristoph Hellwig { 618f461d2dcSChristoph Hellwig unsigned long lval; 619f461d2dcSChristoph Hellwig int err = 0; 620f461d2dcSChristoph Hellwig size_t left; 621f461d2dcSChristoph Hellwig 622f461d2dcSChristoph Hellwig left = *lenp; 623f461d2dcSChristoph Hellwig 624f461d2dcSChristoph Hellwig if (conv(&lval, tbl_data, 0, data)) { 625f461d2dcSChristoph Hellwig err = -EINVAL; 626f461d2dcSChristoph Hellwig goto out; 627f461d2dcSChristoph Hellwig } 628f461d2dcSChristoph Hellwig 62932927393SChristoph Hellwig proc_put_long(&buffer, &left, lval, false); 63032927393SChristoph Hellwig if (!left) 631f461d2dcSChristoph Hellwig goto out; 632f461d2dcSChristoph Hellwig 63332927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 634f461d2dcSChristoph Hellwig 635f461d2dcSChristoph Hellwig out: 636f461d2dcSChristoph Hellwig *lenp -= left; 637f461d2dcSChristoph Hellwig *ppos += *lenp; 638f461d2dcSChristoph Hellwig 639f461d2dcSChristoph Hellwig return err; 640f461d2dcSChristoph Hellwig } 641f461d2dcSChristoph Hellwig 64232fe9152SThomas Weißschuh static int __do_proc_douintvec(void *tbl_data, const struct ctl_table *table, 64332927393SChristoph Hellwig int write, void *buffer, 644f461d2dcSChristoph Hellwig size_t *lenp, loff_t *ppos, 645f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 646f461d2dcSChristoph Hellwig unsigned int *valp, 647f461d2dcSChristoph Hellwig int write, void *data), 648f461d2dcSChristoph Hellwig void *data) 649f461d2dcSChristoph Hellwig { 650f461d2dcSChristoph Hellwig unsigned int *i, vleft; 651f461d2dcSChristoph Hellwig 652f461d2dcSChristoph Hellwig if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 653f461d2dcSChristoph Hellwig *lenp = 0; 654f461d2dcSChristoph Hellwig return 0; 655f461d2dcSChristoph Hellwig } 656f461d2dcSChristoph Hellwig 657f461d2dcSChristoph Hellwig i = (unsigned int *) tbl_data; 658f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(*i); 659f461d2dcSChristoph Hellwig 660f461d2dcSChristoph Hellwig /* 661f461d2dcSChristoph Hellwig * Arrays are not supported, keep this simple. *Do not* add 662f461d2dcSChristoph Hellwig * support for them. 663f461d2dcSChristoph Hellwig */ 664f461d2dcSChristoph Hellwig if (vleft != 1) { 665f461d2dcSChristoph Hellwig *lenp = 0; 666f461d2dcSChristoph Hellwig return -EINVAL; 667f461d2dcSChristoph Hellwig } 668f461d2dcSChristoph Hellwig 669f461d2dcSChristoph Hellwig if (!conv) 670f461d2dcSChristoph Hellwig conv = do_proc_douintvec_conv; 671f461d2dcSChristoph Hellwig 672f461d2dcSChristoph Hellwig if (write) 673f461d2dcSChristoph Hellwig return do_proc_douintvec_w(i, table, buffer, lenp, ppos, 674f461d2dcSChristoph Hellwig conv, data); 675f461d2dcSChristoph Hellwig return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data); 676f461d2dcSChristoph Hellwig } 677f461d2dcSChristoph Hellwig 67832fe9152SThomas Weißschuh int do_proc_douintvec(const struct ctl_table *table, int write, 67932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, 680f461d2dcSChristoph Hellwig int (*conv)(unsigned long *lvalp, 681f461d2dcSChristoph Hellwig unsigned int *valp, 682f461d2dcSChristoph Hellwig int write, void *data), 683f461d2dcSChristoph Hellwig void *data) 684f461d2dcSChristoph Hellwig { 685f461d2dcSChristoph Hellwig return __do_proc_douintvec(table->data, table, write, 686f461d2dcSChristoph Hellwig buffer, lenp, ppos, conv, data); 687f461d2dcSChristoph Hellwig } 688f461d2dcSChristoph Hellwig 689f461d2dcSChristoph Hellwig /** 690a2071573SJia He * proc_dobool - read/write a bool 691a2071573SJia He * @table: the sysctl table 692a2071573SJia He * @write: %TRUE if this is a write to the sysctl file 693a2071573SJia He * @buffer: the user buffer 694a2071573SJia He * @lenp: the size of the user buffer 695a2071573SJia He * @ppos: file position 696a2071573SJia He * 697f1aa2eb5SOndrej Mosnacek * Reads/writes one integer value from/to the user buffer, 698f1aa2eb5SOndrej Mosnacek * treated as an ASCII string. 699f1aa2eb5SOndrej Mosnacek * 700f1aa2eb5SOndrej Mosnacek * table->data must point to a bool variable and table->maxlen must 701f1aa2eb5SOndrej Mosnacek * be sizeof(bool). 702a2071573SJia He * 703a2071573SJia He * Returns 0 on success. 704a2071573SJia He */ 705*78eb4ea2SJoel Granados int proc_dobool(const struct ctl_table *table, int write, void *buffer, 706a2071573SJia He size_t *lenp, loff_t *ppos) 707a2071573SJia He { 708f1aa2eb5SOndrej Mosnacek struct ctl_table tmp; 709f1aa2eb5SOndrej Mosnacek bool *data = table->data; 710f1aa2eb5SOndrej Mosnacek int res, val; 711f1aa2eb5SOndrej Mosnacek 712f1aa2eb5SOndrej Mosnacek /* Do not support arrays yet. */ 713f1aa2eb5SOndrej Mosnacek if (table->maxlen != sizeof(bool)) 714f1aa2eb5SOndrej Mosnacek return -EINVAL; 715f1aa2eb5SOndrej Mosnacek 716f1aa2eb5SOndrej Mosnacek tmp = *table; 717f1aa2eb5SOndrej Mosnacek tmp.maxlen = sizeof(val); 718f1aa2eb5SOndrej Mosnacek tmp.data = &val; 719f1aa2eb5SOndrej Mosnacek 720f1aa2eb5SOndrej Mosnacek val = READ_ONCE(*data); 721f1aa2eb5SOndrej Mosnacek res = proc_dointvec(&tmp, write, buffer, lenp, ppos); 722f1aa2eb5SOndrej Mosnacek if (res) 723f1aa2eb5SOndrej Mosnacek return res; 724f1aa2eb5SOndrej Mosnacek if (write) 725f1aa2eb5SOndrej Mosnacek WRITE_ONCE(*data, val); 726f1aa2eb5SOndrej Mosnacek return 0; 727a2071573SJia He } 728a2071573SJia He 729a2071573SJia He /** 730f461d2dcSChristoph Hellwig * proc_dointvec - read a vector of integers 731f461d2dcSChristoph Hellwig * @table: the sysctl table 732f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 733f461d2dcSChristoph Hellwig * @buffer: the user buffer 734f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 735f461d2dcSChristoph Hellwig * @ppos: file position 736f461d2dcSChristoph Hellwig * 737f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 738f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 739f461d2dcSChristoph Hellwig * 740f461d2dcSChristoph Hellwig * Returns 0 on success. 741f461d2dcSChristoph Hellwig */ 742*78eb4ea2SJoel Granados int proc_dointvec(const struct ctl_table *table, int write, void *buffer, 74332927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 744f461d2dcSChristoph Hellwig { 745f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); 746f461d2dcSChristoph Hellwig } 747f461d2dcSChristoph Hellwig 748f461d2dcSChristoph Hellwig /** 749f461d2dcSChristoph Hellwig * proc_douintvec - read a vector of unsigned integers 750f461d2dcSChristoph Hellwig * @table: the sysctl table 751f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 752f461d2dcSChristoph Hellwig * @buffer: the user buffer 753f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 754f461d2dcSChristoph Hellwig * @ppos: file position 755f461d2dcSChristoph Hellwig * 756f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer 757f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 758f461d2dcSChristoph Hellwig * 759f461d2dcSChristoph Hellwig * Returns 0 on success. 760f461d2dcSChristoph Hellwig */ 761*78eb4ea2SJoel Granados int proc_douintvec(const struct ctl_table *table, int write, void *buffer, 76232927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 763f461d2dcSChristoph Hellwig { 764f461d2dcSChristoph Hellwig return do_proc_douintvec(table, write, buffer, lenp, ppos, 765f461d2dcSChristoph Hellwig do_proc_douintvec_conv, NULL); 766f461d2dcSChristoph Hellwig } 767f461d2dcSChristoph Hellwig 768f461d2dcSChristoph Hellwig /* 769f461d2dcSChristoph Hellwig * Taint values can only be increased 770f461d2dcSChristoph Hellwig * This means we can safely use a temporary. 771f461d2dcSChristoph Hellwig */ 772*78eb4ea2SJoel Granados static int proc_taint(const struct ctl_table *table, int write, 77332927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 774f461d2dcSChristoph Hellwig { 775f461d2dcSChristoph Hellwig struct ctl_table t; 776f461d2dcSChristoph Hellwig unsigned long tmptaint = get_taint(); 777f461d2dcSChristoph Hellwig int err; 778f461d2dcSChristoph Hellwig 779f461d2dcSChristoph Hellwig if (write && !capable(CAP_SYS_ADMIN)) 780f461d2dcSChristoph Hellwig return -EPERM; 781f461d2dcSChristoph Hellwig 782f461d2dcSChristoph Hellwig t = *table; 783f461d2dcSChristoph Hellwig t.data = &tmptaint; 784f461d2dcSChristoph Hellwig err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); 785f461d2dcSChristoph Hellwig if (err < 0) 786f461d2dcSChristoph Hellwig return err; 787f461d2dcSChristoph Hellwig 788f461d2dcSChristoph Hellwig if (write) { 789db38d5c1SRafael Aquini int i; 790db38d5c1SRafael Aquini 791db38d5c1SRafael Aquini /* 792db38d5c1SRafael Aquini * If we are relying on panic_on_taint not producing 793db38d5c1SRafael Aquini * false positives due to userspace input, bail out 794db38d5c1SRafael Aquini * before setting the requested taint flags. 795db38d5c1SRafael Aquini */ 796db38d5c1SRafael Aquini if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint)) 797db38d5c1SRafael Aquini return -EINVAL; 798db38d5c1SRafael Aquini 799f461d2dcSChristoph Hellwig /* 800f461d2dcSChristoph Hellwig * Poor man's atomic or. Not worth adding a primitive 801f461d2dcSChristoph Hellwig * to everyone's atomic.h for this 802f461d2dcSChristoph Hellwig */ 803e77132e7SRafael Aquini for (i = 0; i < TAINT_FLAGS_COUNT; i++) 804e77132e7SRafael Aquini if ((1UL << i) & tmptaint) 805f461d2dcSChristoph Hellwig add_taint(i, LOCKDEP_STILL_OK); 806f461d2dcSChristoph Hellwig } 807f461d2dcSChristoph Hellwig 808f461d2dcSChristoph Hellwig return err; 809f461d2dcSChristoph Hellwig } 810f461d2dcSChristoph Hellwig 811f461d2dcSChristoph Hellwig /** 812f461d2dcSChristoph Hellwig * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure 813f461d2dcSChristoph Hellwig * @min: pointer to minimum allowable value 814f461d2dcSChristoph Hellwig * @max: pointer to maximum allowable value 815f461d2dcSChristoph Hellwig * 816f461d2dcSChristoph Hellwig * The do_proc_dointvec_minmax_conv_param structure provides the 817f461d2dcSChristoph Hellwig * minimum and maximum values for doing range checking for those sysctl 818f461d2dcSChristoph Hellwig * parameters that use the proc_dointvec_minmax() handler. 819f461d2dcSChristoph Hellwig */ 820f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param { 821f461d2dcSChristoph Hellwig int *min; 822f461d2dcSChristoph Hellwig int *max; 823f461d2dcSChristoph Hellwig }; 824f461d2dcSChristoph Hellwig 825f461d2dcSChristoph Hellwig static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, 826f461d2dcSChristoph Hellwig int *valp, 827f461d2dcSChristoph Hellwig int write, void *data) 828f461d2dcSChristoph Hellwig { 829f461d2dcSChristoph Hellwig int tmp, ret; 830f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param *param = data; 831f461d2dcSChristoph Hellwig /* 832f461d2dcSChristoph Hellwig * If writing, first do so via a temporary local int so we can 833f461d2dcSChristoph Hellwig * bounds-check it before touching *valp. 834f461d2dcSChristoph Hellwig */ 835f461d2dcSChristoph Hellwig int *ip = write ? &tmp : valp; 836f461d2dcSChristoph Hellwig 837f461d2dcSChristoph Hellwig ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data); 838f461d2dcSChristoph Hellwig if (ret) 839f461d2dcSChristoph Hellwig return ret; 840f461d2dcSChristoph Hellwig 841f461d2dcSChristoph Hellwig if (write) { 842f461d2dcSChristoph Hellwig if ((param->min && *param->min > tmp) || 843f461d2dcSChristoph Hellwig (param->max && *param->max < tmp)) 844f461d2dcSChristoph Hellwig return -EINVAL; 845f613d86dSKuniyuki Iwashima WRITE_ONCE(*valp, tmp); 846f461d2dcSChristoph Hellwig } 847f461d2dcSChristoph Hellwig 848f461d2dcSChristoph Hellwig return 0; 849f461d2dcSChristoph Hellwig } 850f461d2dcSChristoph Hellwig 851f461d2dcSChristoph Hellwig /** 852f461d2dcSChristoph Hellwig * proc_dointvec_minmax - read a vector of integers with min/max values 853f461d2dcSChristoph Hellwig * @table: the sysctl table 854f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 855f461d2dcSChristoph Hellwig * @buffer: the user buffer 856f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 857f461d2dcSChristoph Hellwig * @ppos: file position 858f461d2dcSChristoph Hellwig * 859f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 860f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 861f461d2dcSChristoph Hellwig * 862f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 863f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). 864f461d2dcSChristoph Hellwig * 865f461d2dcSChristoph Hellwig * Returns 0 on success or -EINVAL on write when the range check fails. 866f461d2dcSChristoph Hellwig */ 867*78eb4ea2SJoel Granados int proc_dointvec_minmax(const struct ctl_table *table, int write, 86832927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 869f461d2dcSChristoph Hellwig { 870f461d2dcSChristoph Hellwig struct do_proc_dointvec_minmax_conv_param param = { 871f461d2dcSChristoph Hellwig .min = (int *) table->extra1, 872f461d2dcSChristoph Hellwig .max = (int *) table->extra2, 873f461d2dcSChristoph Hellwig }; 874f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, 875f461d2dcSChristoph Hellwig do_proc_dointvec_minmax_conv, ¶m); 876f461d2dcSChristoph Hellwig } 877f461d2dcSChristoph Hellwig 878f461d2dcSChristoph Hellwig /** 879f461d2dcSChristoph Hellwig * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure 880f461d2dcSChristoph Hellwig * @min: pointer to minimum allowable value 881f461d2dcSChristoph Hellwig * @max: pointer to maximum allowable value 882f461d2dcSChristoph Hellwig * 883f461d2dcSChristoph Hellwig * The do_proc_douintvec_minmax_conv_param structure provides the 884f461d2dcSChristoph Hellwig * minimum and maximum values for doing range checking for those sysctl 885f461d2dcSChristoph Hellwig * parameters that use the proc_douintvec_minmax() handler. 886f461d2dcSChristoph Hellwig */ 887f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param { 888f461d2dcSChristoph Hellwig unsigned int *min; 889f461d2dcSChristoph Hellwig unsigned int *max; 890f461d2dcSChristoph Hellwig }; 891f461d2dcSChristoph Hellwig 892f461d2dcSChristoph Hellwig static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, 893f461d2dcSChristoph Hellwig unsigned int *valp, 894f461d2dcSChristoph Hellwig int write, void *data) 895f461d2dcSChristoph Hellwig { 896f461d2dcSChristoph Hellwig int ret; 897f461d2dcSChristoph Hellwig unsigned int tmp; 898f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param *param = data; 899f461d2dcSChristoph Hellwig /* write via temporary local uint for bounds-checking */ 900f461d2dcSChristoph Hellwig unsigned int *up = write ? &tmp : valp; 901f461d2dcSChristoph Hellwig 902f461d2dcSChristoph Hellwig ret = do_proc_douintvec_conv(lvalp, up, write, data); 903f461d2dcSChristoph Hellwig if (ret) 904f461d2dcSChristoph Hellwig return ret; 905f461d2dcSChristoph Hellwig 906f461d2dcSChristoph Hellwig if (write) { 907f461d2dcSChristoph Hellwig if ((param->min && *param->min > tmp) || 908f461d2dcSChristoph Hellwig (param->max && *param->max < tmp)) 909f461d2dcSChristoph Hellwig return -ERANGE; 910f461d2dcSChristoph Hellwig 9112d3b559dSKuniyuki Iwashima WRITE_ONCE(*valp, tmp); 912f461d2dcSChristoph Hellwig } 913f461d2dcSChristoph Hellwig 914f461d2dcSChristoph Hellwig return 0; 915f461d2dcSChristoph Hellwig } 916f461d2dcSChristoph Hellwig 917f461d2dcSChristoph Hellwig /** 918f461d2dcSChristoph Hellwig * proc_douintvec_minmax - read a vector of unsigned ints with min/max values 919f461d2dcSChristoph Hellwig * @table: the sysctl table 920f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 921f461d2dcSChristoph Hellwig * @buffer: the user buffer 922f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 923f461d2dcSChristoph Hellwig * @ppos: file position 924f461d2dcSChristoph Hellwig * 925f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer 926f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. Negative 927f461d2dcSChristoph Hellwig * strings are not allowed. 928f461d2dcSChristoph Hellwig * 929f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 930f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). There is a final sanity 931f461d2dcSChristoph Hellwig * check for UINT_MAX to avoid having to support wrap around uses from 932f461d2dcSChristoph Hellwig * userspace. 933f461d2dcSChristoph Hellwig * 934f461d2dcSChristoph Hellwig * Returns 0 on success or -ERANGE on write when the range check fails. 935f461d2dcSChristoph Hellwig */ 936*78eb4ea2SJoel Granados int proc_douintvec_minmax(const struct ctl_table *table, int write, 93732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 938f461d2dcSChristoph Hellwig { 939f461d2dcSChristoph Hellwig struct do_proc_douintvec_minmax_conv_param param = { 940f461d2dcSChristoph Hellwig .min = (unsigned int *) table->extra1, 941f461d2dcSChristoph Hellwig .max = (unsigned int *) table->extra2, 942f461d2dcSChristoph Hellwig }; 943f461d2dcSChristoph Hellwig return do_proc_douintvec(table, write, buffer, lenp, ppos, 944f461d2dcSChristoph Hellwig do_proc_douintvec_minmax_conv, ¶m); 945f461d2dcSChristoph Hellwig } 946f461d2dcSChristoph Hellwig 947cb944413SEric Dumazet /** 948cb944413SEric Dumazet * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values 949cb944413SEric Dumazet * @table: the sysctl table 950cb944413SEric Dumazet * @write: %TRUE if this is a write to the sysctl file 951cb944413SEric Dumazet * @buffer: the user buffer 952cb944413SEric Dumazet * @lenp: the size of the user buffer 953cb944413SEric Dumazet * @ppos: file position 954cb944413SEric Dumazet * 955cb944413SEric Dumazet * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars 956cb944413SEric Dumazet * values from/to the user buffer, treated as an ASCII string. Negative 957cb944413SEric Dumazet * strings are not allowed. 958cb944413SEric Dumazet * 959cb944413SEric Dumazet * This routine will ensure the values are within the range specified by 960cb944413SEric Dumazet * table->extra1 (min) and table->extra2 (max). 961cb944413SEric Dumazet * 962cb944413SEric Dumazet * Returns 0 on success or an error on write when the range check fails. 963cb944413SEric Dumazet */ 964*78eb4ea2SJoel Granados int proc_dou8vec_minmax(const struct ctl_table *table, int write, 965cb944413SEric Dumazet void *buffer, size_t *lenp, loff_t *ppos) 966cb944413SEric Dumazet { 967cb944413SEric Dumazet struct ctl_table tmp; 968cb944413SEric Dumazet unsigned int min = 0, max = 255U, val; 969cb944413SEric Dumazet u8 *data = table->data; 970cb944413SEric Dumazet struct do_proc_douintvec_minmax_conv_param param = { 971cb944413SEric Dumazet .min = &min, 972cb944413SEric Dumazet .max = &max, 973cb944413SEric Dumazet }; 974cb944413SEric Dumazet int res; 975cb944413SEric Dumazet 976cb944413SEric Dumazet /* Do not support arrays yet. */ 977cb944413SEric Dumazet if (table->maxlen != sizeof(u8)) 978cb944413SEric Dumazet return -EINVAL; 979cb944413SEric Dumazet 980b5ffbd13SWen Yang if (table->extra1) 981cb944413SEric Dumazet min = *(unsigned int *) table->extra1; 982b5ffbd13SWen Yang if (table->extra2) 983cb944413SEric Dumazet max = *(unsigned int *) table->extra2; 984cb944413SEric Dumazet 985cb944413SEric Dumazet tmp = *table; 986cb944413SEric Dumazet 987cb944413SEric Dumazet tmp.maxlen = sizeof(val); 988cb944413SEric Dumazet tmp.data = &val; 9897dee5d77SKuniyuki Iwashima val = READ_ONCE(*data); 990cb944413SEric Dumazet res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos, 991cb944413SEric Dumazet do_proc_douintvec_minmax_conv, ¶m); 992cb944413SEric Dumazet if (res) 993cb944413SEric Dumazet return res; 994cb944413SEric Dumazet if (write) 9957dee5d77SKuniyuki Iwashima WRITE_ONCE(*data, val); 996cb944413SEric Dumazet return 0; 997cb944413SEric Dumazet } 998cb944413SEric Dumazet EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); 999cb944413SEric Dumazet 1000f461d2dcSChristoph Hellwig #ifdef CONFIG_MAGIC_SYSRQ 1001*78eb4ea2SJoel Granados static int sysrq_sysctl_handler(const struct ctl_table *table, int write, 100232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1003f461d2dcSChristoph Hellwig { 1004f461d2dcSChristoph Hellwig int tmp, ret; 1005f461d2dcSChristoph Hellwig 1006f461d2dcSChristoph Hellwig tmp = sysrq_mask(); 1007f461d2dcSChristoph Hellwig 1008f461d2dcSChristoph Hellwig ret = __do_proc_dointvec(&tmp, table, write, buffer, 1009f461d2dcSChristoph Hellwig lenp, ppos, NULL, NULL); 1010f461d2dcSChristoph Hellwig if (ret || !write) 1011f461d2dcSChristoph Hellwig return ret; 1012f461d2dcSChristoph Hellwig 1013f461d2dcSChristoph Hellwig if (write) 1014f461d2dcSChristoph Hellwig sysrq_toggle_support(tmp); 1015f461d2dcSChristoph Hellwig 1016f461d2dcSChristoph Hellwig return 0; 1017f461d2dcSChristoph Hellwig } 1018f461d2dcSChristoph Hellwig #endif 1019f461d2dcSChristoph Hellwig 102032fe9152SThomas Weißschuh static int __do_proc_doulongvec_minmax(void *data, 102132fe9152SThomas Weißschuh const struct ctl_table *table, int write, 102232fe9152SThomas Weißschuh void *buffer, size_t *lenp, loff_t *ppos, 102332927393SChristoph Hellwig unsigned long convmul, unsigned long convdiv) 1024f461d2dcSChristoph Hellwig { 1025f461d2dcSChristoph Hellwig unsigned long *i, *min, *max; 1026f461d2dcSChristoph Hellwig int vleft, first = 1, err = 0; 1027f461d2dcSChristoph Hellwig size_t left; 102832927393SChristoph Hellwig char *p; 1029f461d2dcSChristoph Hellwig 1030f461d2dcSChristoph Hellwig if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { 1031f461d2dcSChristoph Hellwig *lenp = 0; 1032f461d2dcSChristoph Hellwig return 0; 1033f461d2dcSChristoph Hellwig } 1034f461d2dcSChristoph Hellwig 10358ebc4123SDong Chuanjian i = data; 10368ebc4123SDong Chuanjian min = table->extra1; 10378ebc4123SDong Chuanjian max = table->extra2; 1038f461d2dcSChristoph Hellwig vleft = table->maxlen / sizeof(unsigned long); 1039f461d2dcSChristoph Hellwig left = *lenp; 1040f461d2dcSChristoph Hellwig 1041f461d2dcSChristoph Hellwig if (write) { 1042f461d2dcSChristoph Hellwig if (proc_first_pos_non_zero_ignore(ppos, table)) 1043f461d2dcSChristoph Hellwig goto out; 1044f461d2dcSChristoph Hellwig 1045f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) 1046f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 104732927393SChristoph Hellwig p = buffer; 1048f461d2dcSChristoph Hellwig } 1049f461d2dcSChristoph Hellwig 1050f461d2dcSChristoph Hellwig for (; left && vleft--; i++, first = 0) { 1051f461d2dcSChristoph Hellwig unsigned long val; 1052f461d2dcSChristoph Hellwig 1053f461d2dcSChristoph Hellwig if (write) { 1054f461d2dcSChristoph Hellwig bool neg; 1055f461d2dcSChristoph Hellwig 1056bce93322SLinus Torvalds proc_skip_spaces(&p, &left); 1057f461d2dcSChristoph Hellwig if (!left) 1058f461d2dcSChristoph Hellwig break; 1059f461d2dcSChristoph Hellwig 1060f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val, &neg, 1061f461d2dcSChristoph Hellwig proc_wspace_sep, 1062f461d2dcSChristoph Hellwig sizeof(proc_wspace_sep), NULL); 10631622ed7dSBaokun Li if (err || neg) { 10641622ed7dSBaokun Li err = -EINVAL; 1065f461d2dcSChristoph Hellwig break; 10661622ed7dSBaokun Li } 10671622ed7dSBaokun Li 1068f461d2dcSChristoph Hellwig val = convmul * val / convdiv; 1069f461d2dcSChristoph Hellwig if ((min && val < *min) || (max && val > *max)) { 1070f461d2dcSChristoph Hellwig err = -EINVAL; 1071f461d2dcSChristoph Hellwig break; 1072f461d2dcSChristoph Hellwig } 1073c31bcc8fSKuniyuki Iwashima WRITE_ONCE(*i, val); 1074f461d2dcSChristoph Hellwig } else { 1075c31bcc8fSKuniyuki Iwashima val = convdiv * READ_ONCE(*i) / convmul; 107632927393SChristoph Hellwig if (!first) 107732927393SChristoph Hellwig proc_put_char(&buffer, &left, '\t'); 107832927393SChristoph Hellwig proc_put_long(&buffer, &left, val, false); 1079f461d2dcSChristoph Hellwig } 1080f461d2dcSChristoph Hellwig } 1081f461d2dcSChristoph Hellwig 1082f461d2dcSChristoph Hellwig if (!write && !first && left && !err) 108332927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 1084f461d2dcSChristoph Hellwig if (write && !err) 1085bce93322SLinus Torvalds proc_skip_spaces(&p, &left); 108632927393SChristoph Hellwig if (write && first) 1087f461d2dcSChristoph Hellwig return err ? : -EINVAL; 1088f461d2dcSChristoph Hellwig *lenp -= left; 1089f461d2dcSChristoph Hellwig out: 1090f461d2dcSChristoph Hellwig *ppos += *lenp; 1091f461d2dcSChristoph Hellwig return err; 1092f461d2dcSChristoph Hellwig } 1093f461d2dcSChristoph Hellwig 109432fe9152SThomas Weißschuh static int do_proc_doulongvec_minmax(const struct ctl_table *table, int write, 109532927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, 1096f461d2dcSChristoph Hellwig unsigned long convdiv) 1097f461d2dcSChristoph Hellwig { 1098f461d2dcSChristoph Hellwig return __do_proc_doulongvec_minmax(table->data, table, write, 1099f461d2dcSChristoph Hellwig buffer, lenp, ppos, convmul, convdiv); 1100f461d2dcSChristoph Hellwig } 1101f461d2dcSChristoph Hellwig 1102f461d2dcSChristoph Hellwig /** 1103f461d2dcSChristoph Hellwig * proc_doulongvec_minmax - read a vector of long integers with min/max values 1104f461d2dcSChristoph Hellwig * @table: the sysctl table 1105f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1106f461d2dcSChristoph Hellwig * @buffer: the user buffer 1107f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1108f461d2dcSChristoph Hellwig * @ppos: file position 1109f461d2dcSChristoph Hellwig * 1110f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 1111f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1112f461d2dcSChristoph Hellwig * 1113f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 1114f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). 1115f461d2dcSChristoph Hellwig * 1116f461d2dcSChristoph Hellwig * Returns 0 on success. 1117f461d2dcSChristoph Hellwig */ 1118*78eb4ea2SJoel Granados int proc_doulongvec_minmax(const struct ctl_table *table, int write, 111932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1120f461d2dcSChristoph Hellwig { 1121f461d2dcSChristoph Hellwig return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); 1122f461d2dcSChristoph Hellwig } 1123f461d2dcSChristoph Hellwig 1124f461d2dcSChristoph Hellwig /** 1125f461d2dcSChristoph Hellwig * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 1126f461d2dcSChristoph Hellwig * @table: the sysctl table 1127f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1128f461d2dcSChristoph Hellwig * @buffer: the user buffer 1129f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1130f461d2dcSChristoph Hellwig * @ppos: file position 1131f461d2dcSChristoph Hellwig * 1132f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 1133f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. The values 1134f461d2dcSChristoph Hellwig * are treated as milliseconds, and converted to jiffies when they are stored. 1135f461d2dcSChristoph Hellwig * 1136f461d2dcSChristoph Hellwig * This routine will ensure the values are within the range specified by 1137f461d2dcSChristoph Hellwig * table->extra1 (min) and table->extra2 (max). 1138f461d2dcSChristoph Hellwig * 1139f461d2dcSChristoph Hellwig * Returns 0 on success. 1140f461d2dcSChristoph Hellwig */ 1141*78eb4ea2SJoel Granados int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write, 114232927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1143f461d2dcSChristoph Hellwig { 1144f461d2dcSChristoph Hellwig return do_proc_doulongvec_minmax(table, write, buffer, 1145f461d2dcSChristoph Hellwig lenp, ppos, HZ, 1000l); 1146f461d2dcSChristoph Hellwig } 1147f461d2dcSChristoph Hellwig 1148f461d2dcSChristoph Hellwig 1149f461d2dcSChristoph Hellwig static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, 1150f461d2dcSChristoph Hellwig int *valp, 1151f461d2dcSChristoph Hellwig int write, void *data) 1152f461d2dcSChristoph Hellwig { 1153f461d2dcSChristoph Hellwig if (write) { 1154f461d2dcSChristoph Hellwig if (*lvalp > INT_MAX / HZ) 1155f461d2dcSChristoph Hellwig return 1; 1156e8778208SKuniyuki Iwashima if (*negp) 1157e8778208SKuniyuki Iwashima WRITE_ONCE(*valp, -*lvalp * HZ); 1158e8778208SKuniyuki Iwashima else 1159e8778208SKuniyuki Iwashima WRITE_ONCE(*valp, *lvalp * HZ); 1160f461d2dcSChristoph Hellwig } else { 1161e8778208SKuniyuki Iwashima int val = READ_ONCE(*valp); 1162f461d2dcSChristoph Hellwig unsigned long lval; 1163f461d2dcSChristoph Hellwig if (val < 0) { 1164f461d2dcSChristoph Hellwig *negp = true; 1165f461d2dcSChristoph Hellwig lval = -(unsigned long)val; 1166f461d2dcSChristoph Hellwig } else { 1167f461d2dcSChristoph Hellwig *negp = false; 1168f461d2dcSChristoph Hellwig lval = (unsigned long)val; 1169f461d2dcSChristoph Hellwig } 1170f461d2dcSChristoph Hellwig *lvalp = lval / HZ; 1171f461d2dcSChristoph Hellwig } 1172f461d2dcSChristoph Hellwig return 0; 1173f461d2dcSChristoph Hellwig } 1174f461d2dcSChristoph Hellwig 1175f461d2dcSChristoph Hellwig static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, 1176f461d2dcSChristoph Hellwig int *valp, 1177f461d2dcSChristoph Hellwig int write, void *data) 1178f461d2dcSChristoph Hellwig { 1179f461d2dcSChristoph Hellwig if (write) { 1180f461d2dcSChristoph Hellwig if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 1181f461d2dcSChristoph Hellwig return 1; 1182f461d2dcSChristoph Hellwig *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 1183f461d2dcSChristoph Hellwig } else { 1184f461d2dcSChristoph Hellwig int val = *valp; 1185f461d2dcSChristoph Hellwig unsigned long lval; 1186f461d2dcSChristoph Hellwig if (val < 0) { 1187f461d2dcSChristoph Hellwig *negp = true; 1188f461d2dcSChristoph Hellwig lval = -(unsigned long)val; 1189f461d2dcSChristoph Hellwig } else { 1190f461d2dcSChristoph Hellwig *negp = false; 1191f461d2dcSChristoph Hellwig lval = (unsigned long)val; 1192f461d2dcSChristoph Hellwig } 1193f461d2dcSChristoph Hellwig *lvalp = jiffies_to_clock_t(lval); 1194f461d2dcSChristoph Hellwig } 1195f461d2dcSChristoph Hellwig return 0; 1196f461d2dcSChristoph Hellwig } 1197f461d2dcSChristoph Hellwig 1198f461d2dcSChristoph Hellwig static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, 1199f461d2dcSChristoph Hellwig int *valp, 1200f461d2dcSChristoph Hellwig int write, void *data) 1201f461d2dcSChristoph Hellwig { 1202f461d2dcSChristoph Hellwig if (write) { 1203f461d2dcSChristoph Hellwig unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 1204f461d2dcSChristoph Hellwig 1205f461d2dcSChristoph Hellwig if (jif > INT_MAX) 1206f461d2dcSChristoph Hellwig return 1; 12077d1025e5SKuniyuki Iwashima WRITE_ONCE(*valp, (int)jif); 1208f461d2dcSChristoph Hellwig } else { 12097d1025e5SKuniyuki Iwashima int val = READ_ONCE(*valp); 1210f461d2dcSChristoph Hellwig unsigned long lval; 1211f461d2dcSChristoph Hellwig if (val < 0) { 1212f461d2dcSChristoph Hellwig *negp = true; 1213f461d2dcSChristoph Hellwig lval = -(unsigned long)val; 1214f461d2dcSChristoph Hellwig } else { 1215f461d2dcSChristoph Hellwig *negp = false; 1216f461d2dcSChristoph Hellwig lval = (unsigned long)val; 1217f461d2dcSChristoph Hellwig } 1218f461d2dcSChristoph Hellwig *lvalp = jiffies_to_msecs(lval); 1219f461d2dcSChristoph Hellwig } 1220f461d2dcSChristoph Hellwig return 0; 1221f461d2dcSChristoph Hellwig } 1222f461d2dcSChristoph Hellwig 1223c381d02bSYuwei Wang static int do_proc_dointvec_ms_jiffies_minmax_conv(bool *negp, unsigned long *lvalp, 1224c381d02bSYuwei Wang int *valp, int write, void *data) 1225c381d02bSYuwei Wang { 1226c381d02bSYuwei Wang int tmp, ret; 1227c381d02bSYuwei Wang struct do_proc_dointvec_minmax_conv_param *param = data; 1228c381d02bSYuwei Wang /* 1229c381d02bSYuwei Wang * If writing, first do so via a temporary local int so we can 1230c381d02bSYuwei Wang * bounds-check it before touching *valp. 1231c381d02bSYuwei Wang */ 1232c381d02bSYuwei Wang int *ip = write ? &tmp : valp; 1233c381d02bSYuwei Wang 1234c381d02bSYuwei Wang ret = do_proc_dointvec_ms_jiffies_conv(negp, lvalp, ip, write, data); 1235c381d02bSYuwei Wang if (ret) 1236c381d02bSYuwei Wang return ret; 1237c381d02bSYuwei Wang 1238c381d02bSYuwei Wang if (write) { 1239c381d02bSYuwei Wang if ((param->min && *param->min > tmp) || 1240c381d02bSYuwei Wang (param->max && *param->max < tmp)) 1241c381d02bSYuwei Wang return -EINVAL; 1242c381d02bSYuwei Wang *valp = tmp; 1243c381d02bSYuwei Wang } 1244c381d02bSYuwei Wang return 0; 1245c381d02bSYuwei Wang } 1246c381d02bSYuwei Wang 1247f461d2dcSChristoph Hellwig /** 1248f461d2dcSChristoph Hellwig * proc_dointvec_jiffies - read a vector of integers as seconds 1249f461d2dcSChristoph Hellwig * @table: the sysctl table 1250f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1251f461d2dcSChristoph Hellwig * @buffer: the user buffer 1252f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1253f461d2dcSChristoph Hellwig * @ppos: file position 1254f461d2dcSChristoph Hellwig * 1255f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1256f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1257f461d2dcSChristoph Hellwig * The values read are assumed to be in seconds, and are converted into 1258f461d2dcSChristoph Hellwig * jiffies. 1259f461d2dcSChristoph Hellwig * 1260f461d2dcSChristoph Hellwig * Returns 0 on success. 1261f461d2dcSChristoph Hellwig */ 1262*78eb4ea2SJoel Granados int proc_dointvec_jiffies(const struct ctl_table *table, int write, 126332927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1264f461d2dcSChristoph Hellwig { 1265f461d2dcSChristoph Hellwig return do_proc_dointvec(table,write,buffer,lenp,ppos, 1266f461d2dcSChristoph Hellwig do_proc_dointvec_jiffies_conv,NULL); 1267f461d2dcSChristoph Hellwig } 1268f461d2dcSChristoph Hellwig 1269*78eb4ea2SJoel Granados int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write, 1270c381d02bSYuwei Wang void *buffer, size_t *lenp, loff_t *ppos) 1271c381d02bSYuwei Wang { 1272c381d02bSYuwei Wang struct do_proc_dointvec_minmax_conv_param param = { 1273c381d02bSYuwei Wang .min = (int *) table->extra1, 1274c381d02bSYuwei Wang .max = (int *) table->extra2, 1275c381d02bSYuwei Wang }; 1276c381d02bSYuwei Wang return do_proc_dointvec(table, write, buffer, lenp, ppos, 1277c381d02bSYuwei Wang do_proc_dointvec_ms_jiffies_minmax_conv, ¶m); 1278c381d02bSYuwei Wang } 1279c381d02bSYuwei Wang 1280f461d2dcSChristoph Hellwig /** 1281f461d2dcSChristoph Hellwig * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 1282f461d2dcSChristoph Hellwig * @table: the sysctl table 1283f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1284f461d2dcSChristoph Hellwig * @buffer: the user buffer 1285f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1286f461d2dcSChristoph Hellwig * @ppos: pointer to the file position 1287f461d2dcSChristoph Hellwig * 1288f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1289f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1290f461d2dcSChristoph Hellwig * The values read are assumed to be in 1/USER_HZ seconds, and 1291f461d2dcSChristoph Hellwig * are converted into jiffies. 1292f461d2dcSChristoph Hellwig * 1293f461d2dcSChristoph Hellwig * Returns 0 on success. 1294f461d2dcSChristoph Hellwig */ 1295*78eb4ea2SJoel Granados int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write, 129632927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1297f461d2dcSChristoph Hellwig { 1298f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, 1299f461d2dcSChristoph Hellwig do_proc_dointvec_userhz_jiffies_conv, NULL); 1300f461d2dcSChristoph Hellwig } 1301f461d2dcSChristoph Hellwig 1302f461d2dcSChristoph Hellwig /** 1303f461d2dcSChristoph Hellwig * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 1304f461d2dcSChristoph Hellwig * @table: the sysctl table 1305f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1306f461d2dcSChristoph Hellwig * @buffer: the user buffer 1307f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1308f461d2dcSChristoph Hellwig * @ppos: file position 1309f461d2dcSChristoph Hellwig * @ppos: the current position in the file 1310f461d2dcSChristoph Hellwig * 1311f461d2dcSChristoph Hellwig * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1312f461d2dcSChristoph Hellwig * values from/to the user buffer, treated as an ASCII string. 1313f461d2dcSChristoph Hellwig * The values read are assumed to be in 1/1000 seconds, and 1314f461d2dcSChristoph Hellwig * are converted into jiffies. 1315f461d2dcSChristoph Hellwig * 1316f461d2dcSChristoph Hellwig * Returns 0 on success. 1317f461d2dcSChristoph Hellwig */ 1318*78eb4ea2SJoel Granados int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, void *buffer, 131932927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 1320f461d2dcSChristoph Hellwig { 1321f461d2dcSChristoph Hellwig return do_proc_dointvec(table, write, buffer, lenp, ppos, 1322f461d2dcSChristoph Hellwig do_proc_dointvec_ms_jiffies_conv, NULL); 1323f461d2dcSChristoph Hellwig } 1324f461d2dcSChristoph Hellwig 1325*78eb4ea2SJoel Granados static int proc_do_cad_pid(const struct ctl_table *table, int write, void *buffer, 132632927393SChristoph Hellwig size_t *lenp, loff_t *ppos) 1327f461d2dcSChristoph Hellwig { 1328f461d2dcSChristoph Hellwig struct pid *new_pid; 1329f461d2dcSChristoph Hellwig pid_t tmp; 1330f461d2dcSChristoph Hellwig int r; 1331f461d2dcSChristoph Hellwig 1332f461d2dcSChristoph Hellwig tmp = pid_vnr(cad_pid); 1333f461d2dcSChristoph Hellwig 1334f461d2dcSChristoph Hellwig r = __do_proc_dointvec(&tmp, table, write, buffer, 1335f461d2dcSChristoph Hellwig lenp, ppos, NULL, NULL); 1336f461d2dcSChristoph Hellwig if (r || !write) 1337f461d2dcSChristoph Hellwig return r; 1338f461d2dcSChristoph Hellwig 1339f461d2dcSChristoph Hellwig new_pid = find_get_pid(tmp); 1340f461d2dcSChristoph Hellwig if (!new_pid) 1341f461d2dcSChristoph Hellwig return -ESRCH; 1342f461d2dcSChristoph Hellwig 1343f461d2dcSChristoph Hellwig put_pid(xchg(&cad_pid, new_pid)); 1344f461d2dcSChristoph Hellwig return 0; 1345f461d2dcSChristoph Hellwig } 1346f461d2dcSChristoph Hellwig 1347f461d2dcSChristoph Hellwig /** 1348f461d2dcSChristoph Hellwig * proc_do_large_bitmap - read/write from/to a large bitmap 1349f461d2dcSChristoph Hellwig * @table: the sysctl table 1350f461d2dcSChristoph Hellwig * @write: %TRUE if this is a write to the sysctl file 1351f461d2dcSChristoph Hellwig * @buffer: the user buffer 1352f461d2dcSChristoph Hellwig * @lenp: the size of the user buffer 1353f461d2dcSChristoph Hellwig * @ppos: file position 1354f461d2dcSChristoph Hellwig * 1355f461d2dcSChristoph Hellwig * The bitmap is stored at table->data and the bitmap length (in bits) 1356f461d2dcSChristoph Hellwig * in table->maxlen. 1357f461d2dcSChristoph Hellwig * 1358f461d2dcSChristoph Hellwig * We use a range comma separated format (e.g. 1,3-4,10-10) so that 1359f461d2dcSChristoph Hellwig * large bitmaps may be represented in a compact manner. Writing into 1360f461d2dcSChristoph Hellwig * the file will clear the bitmap then update it with the given input. 1361f461d2dcSChristoph Hellwig * 1362f461d2dcSChristoph Hellwig * Returns 0 on success. 1363f461d2dcSChristoph Hellwig */ 1364*78eb4ea2SJoel Granados int proc_do_large_bitmap(const struct ctl_table *table, int write, 136532927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1366f461d2dcSChristoph Hellwig { 1367f461d2dcSChristoph Hellwig int err = 0; 1368f461d2dcSChristoph Hellwig size_t left = *lenp; 1369f461d2dcSChristoph Hellwig unsigned long bitmap_len = table->maxlen; 1370f461d2dcSChristoph Hellwig unsigned long *bitmap = *(unsigned long **) table->data; 1371f461d2dcSChristoph Hellwig unsigned long *tmp_bitmap = NULL; 1372f461d2dcSChristoph Hellwig char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; 1373f461d2dcSChristoph Hellwig 1374f461d2dcSChristoph Hellwig if (!bitmap || !bitmap_len || !left || (*ppos && !write)) { 1375f461d2dcSChristoph Hellwig *lenp = 0; 1376f461d2dcSChristoph Hellwig return 0; 1377f461d2dcSChristoph Hellwig } 1378f461d2dcSChristoph Hellwig 1379f461d2dcSChristoph Hellwig if (write) { 138032927393SChristoph Hellwig char *p = buffer; 1381f461d2dcSChristoph Hellwig size_t skipped = 0; 1382f461d2dcSChristoph Hellwig 1383f461d2dcSChristoph Hellwig if (left > PAGE_SIZE - 1) { 1384f461d2dcSChristoph Hellwig left = PAGE_SIZE - 1; 1385f461d2dcSChristoph Hellwig /* How much of the buffer we'll skip this pass */ 1386f461d2dcSChristoph Hellwig skipped = *lenp - left; 1387f461d2dcSChristoph Hellwig } 1388f461d2dcSChristoph Hellwig 1389f461d2dcSChristoph Hellwig tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL); 139032927393SChristoph Hellwig if (!tmp_bitmap) 1391f461d2dcSChristoph Hellwig return -ENOMEM; 1392f461d2dcSChristoph Hellwig proc_skip_char(&p, &left, '\n'); 1393f461d2dcSChristoph Hellwig while (!err && left) { 1394f461d2dcSChristoph Hellwig unsigned long val_a, val_b; 1395f461d2dcSChristoph Hellwig bool neg; 1396f461d2dcSChristoph Hellwig size_t saved_left; 1397f461d2dcSChristoph Hellwig 1398f461d2dcSChristoph Hellwig /* In case we stop parsing mid-number, we can reset */ 1399f461d2dcSChristoph Hellwig saved_left = left; 1400f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val_a, &neg, tr_a, 1401f461d2dcSChristoph Hellwig sizeof(tr_a), &c); 1402f461d2dcSChristoph Hellwig /* 1403f461d2dcSChristoph Hellwig * If we consumed the entirety of a truncated buffer or 1404f461d2dcSChristoph Hellwig * only one char is left (may be a "-"), then stop here, 1405f461d2dcSChristoph Hellwig * reset, & come back for more. 1406f461d2dcSChristoph Hellwig */ 1407f461d2dcSChristoph Hellwig if ((left <= 1) && skipped) { 1408f461d2dcSChristoph Hellwig left = saved_left; 1409f461d2dcSChristoph Hellwig break; 1410f461d2dcSChristoph Hellwig } 1411f461d2dcSChristoph Hellwig 1412f461d2dcSChristoph Hellwig if (err) 1413f461d2dcSChristoph Hellwig break; 1414f461d2dcSChristoph Hellwig if (val_a >= bitmap_len || neg) { 1415f461d2dcSChristoph Hellwig err = -EINVAL; 1416f461d2dcSChristoph Hellwig break; 1417f461d2dcSChristoph Hellwig } 1418f461d2dcSChristoph Hellwig 1419f461d2dcSChristoph Hellwig val_b = val_a; 1420f461d2dcSChristoph Hellwig if (left) { 1421f461d2dcSChristoph Hellwig p++; 1422f461d2dcSChristoph Hellwig left--; 1423f461d2dcSChristoph Hellwig } 1424f461d2dcSChristoph Hellwig 1425f461d2dcSChristoph Hellwig if (c == '-') { 1426f461d2dcSChristoph Hellwig err = proc_get_long(&p, &left, &val_b, 1427f461d2dcSChristoph Hellwig &neg, tr_b, sizeof(tr_b), 1428f461d2dcSChristoph Hellwig &c); 1429f461d2dcSChristoph Hellwig /* 1430f461d2dcSChristoph Hellwig * If we consumed all of a truncated buffer or 1431f461d2dcSChristoph Hellwig * then stop here, reset, & come back for more. 1432f461d2dcSChristoph Hellwig */ 1433f461d2dcSChristoph Hellwig if (!left && skipped) { 1434f461d2dcSChristoph Hellwig left = saved_left; 1435f461d2dcSChristoph Hellwig break; 1436f461d2dcSChristoph Hellwig } 1437f461d2dcSChristoph Hellwig 1438f461d2dcSChristoph Hellwig if (err) 1439f461d2dcSChristoph Hellwig break; 1440f461d2dcSChristoph Hellwig if (val_b >= bitmap_len || neg || 1441f461d2dcSChristoph Hellwig val_a > val_b) { 1442f461d2dcSChristoph Hellwig err = -EINVAL; 1443f461d2dcSChristoph Hellwig break; 1444f461d2dcSChristoph Hellwig } 1445f461d2dcSChristoph Hellwig if (left) { 1446f461d2dcSChristoph Hellwig p++; 1447f461d2dcSChristoph Hellwig left--; 1448f461d2dcSChristoph Hellwig } 1449f461d2dcSChristoph Hellwig } 1450f461d2dcSChristoph Hellwig 1451f461d2dcSChristoph Hellwig bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); 1452f461d2dcSChristoph Hellwig proc_skip_char(&p, &left, '\n'); 1453f461d2dcSChristoph Hellwig } 1454f461d2dcSChristoph Hellwig left += skipped; 1455f461d2dcSChristoph Hellwig } else { 1456f461d2dcSChristoph Hellwig unsigned long bit_a, bit_b = 0; 14579a52c5f3SJiapeng Chong bool first = 1; 1458f461d2dcSChristoph Hellwig 1459f461d2dcSChristoph Hellwig while (left) { 1460f461d2dcSChristoph Hellwig bit_a = find_next_bit(bitmap, bitmap_len, bit_b); 1461f461d2dcSChristoph Hellwig if (bit_a >= bitmap_len) 1462f461d2dcSChristoph Hellwig break; 1463f461d2dcSChristoph Hellwig bit_b = find_next_zero_bit(bitmap, bitmap_len, 1464f461d2dcSChristoph Hellwig bit_a + 1) - 1; 1465f461d2dcSChristoph Hellwig 146632927393SChristoph Hellwig if (!first) 146732927393SChristoph Hellwig proc_put_char(&buffer, &left, ','); 146832927393SChristoph Hellwig proc_put_long(&buffer, &left, bit_a, false); 1469f461d2dcSChristoph Hellwig if (bit_a != bit_b) { 147032927393SChristoph Hellwig proc_put_char(&buffer, &left, '-'); 147132927393SChristoph Hellwig proc_put_long(&buffer, &left, bit_b, false); 1472f461d2dcSChristoph Hellwig } 1473f461d2dcSChristoph Hellwig 1474f461d2dcSChristoph Hellwig first = 0; bit_b++; 1475f461d2dcSChristoph Hellwig } 147632927393SChristoph Hellwig proc_put_char(&buffer, &left, '\n'); 1477f461d2dcSChristoph Hellwig } 1478f461d2dcSChristoph Hellwig 1479f461d2dcSChristoph Hellwig if (!err) { 1480f461d2dcSChristoph Hellwig if (write) { 1481f461d2dcSChristoph Hellwig if (*ppos) 1482f461d2dcSChristoph Hellwig bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); 1483f461d2dcSChristoph Hellwig else 1484f461d2dcSChristoph Hellwig bitmap_copy(bitmap, tmp_bitmap, bitmap_len); 1485f461d2dcSChristoph Hellwig } 1486f461d2dcSChristoph Hellwig *lenp -= left; 1487f461d2dcSChristoph Hellwig *ppos += *lenp; 1488f461d2dcSChristoph Hellwig } 1489f461d2dcSChristoph Hellwig 1490f461d2dcSChristoph Hellwig bitmap_free(tmp_bitmap); 1491f461d2dcSChristoph Hellwig return err; 1492f461d2dcSChristoph Hellwig } 1493f461d2dcSChristoph Hellwig 1494f461d2dcSChristoph Hellwig #else /* CONFIG_PROC_SYSCTL */ 1495f461d2dcSChristoph Hellwig 1496*78eb4ea2SJoel Granados int proc_dostring(const struct ctl_table *table, int write, 149732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1498f461d2dcSChristoph Hellwig { 1499f461d2dcSChristoph Hellwig return -ENOSYS; 1500f461d2dcSChristoph Hellwig } 1501f461d2dcSChristoph Hellwig 1502*78eb4ea2SJoel Granados int proc_dobool(const struct ctl_table *table, int write, 1503a2071573SJia He void *buffer, size_t *lenp, loff_t *ppos) 1504a2071573SJia He { 1505a2071573SJia He return -ENOSYS; 1506a2071573SJia He } 1507a2071573SJia He 1508*78eb4ea2SJoel Granados int proc_dointvec(const struct ctl_table *table, int write, 150932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1510f461d2dcSChristoph Hellwig { 1511f461d2dcSChristoph Hellwig return -ENOSYS; 1512f461d2dcSChristoph Hellwig } 1513f461d2dcSChristoph Hellwig 1514*78eb4ea2SJoel Granados int proc_douintvec(const struct ctl_table *table, int write, 151532927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1516f461d2dcSChristoph Hellwig { 1517f461d2dcSChristoph Hellwig return -ENOSYS; 1518f461d2dcSChristoph Hellwig } 1519f461d2dcSChristoph Hellwig 1520*78eb4ea2SJoel Granados int proc_dointvec_minmax(const struct ctl_table *table, int write, 152132927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1522f461d2dcSChristoph Hellwig { 1523f461d2dcSChristoph Hellwig return -ENOSYS; 1524f461d2dcSChristoph Hellwig } 1525f461d2dcSChristoph Hellwig 1526*78eb4ea2SJoel Granados int proc_douintvec_minmax(const struct ctl_table *table, int write, 152732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1528f461d2dcSChristoph Hellwig { 1529f461d2dcSChristoph Hellwig return -ENOSYS; 1530f461d2dcSChristoph Hellwig } 1531f461d2dcSChristoph Hellwig 1532*78eb4ea2SJoel Granados int proc_dou8vec_minmax(const struct ctl_table *table, int write, 1533cb944413SEric Dumazet void *buffer, size_t *lenp, loff_t *ppos) 1534cb944413SEric Dumazet { 1535cb944413SEric Dumazet return -ENOSYS; 1536cb944413SEric Dumazet } 1537cb944413SEric Dumazet 1538*78eb4ea2SJoel Granados int proc_dointvec_jiffies(const struct ctl_table *table, int write, 153932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1540f461d2dcSChristoph Hellwig { 1541f461d2dcSChristoph Hellwig return -ENOSYS; 1542f461d2dcSChristoph Hellwig } 1543f461d2dcSChristoph Hellwig 1544*78eb4ea2SJoel Granados int proc_dointvec_ms_jiffies_minmax(const struct ctl_table *table, int write, 1545c381d02bSYuwei Wang void *buffer, size_t *lenp, loff_t *ppos) 1546c381d02bSYuwei Wang { 1547c381d02bSYuwei Wang return -ENOSYS; 1548c381d02bSYuwei Wang } 1549c381d02bSYuwei Wang 1550*78eb4ea2SJoel Granados int proc_dointvec_userhz_jiffies(const struct ctl_table *table, int write, 155132927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1552f461d2dcSChristoph Hellwig { 1553f461d2dcSChristoph Hellwig return -ENOSYS; 1554f461d2dcSChristoph Hellwig } 1555f461d2dcSChristoph Hellwig 1556*78eb4ea2SJoel Granados int proc_dointvec_ms_jiffies(const struct ctl_table *table, int write, 155732927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1558f461d2dcSChristoph Hellwig { 1559f461d2dcSChristoph Hellwig return -ENOSYS; 1560f461d2dcSChristoph Hellwig } 1561f461d2dcSChristoph Hellwig 1562*78eb4ea2SJoel Granados int proc_doulongvec_minmax(const struct ctl_table *table, int write, 156332927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1564f461d2dcSChristoph Hellwig { 1565f461d2dcSChristoph Hellwig return -ENOSYS; 1566f461d2dcSChristoph Hellwig } 1567f461d2dcSChristoph Hellwig 1568*78eb4ea2SJoel Granados int proc_doulongvec_ms_jiffies_minmax(const struct ctl_table *table, int write, 156932927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1570f461d2dcSChristoph Hellwig { 1571f461d2dcSChristoph Hellwig return -ENOSYS; 1572f461d2dcSChristoph Hellwig } 1573f461d2dcSChristoph Hellwig 1574*78eb4ea2SJoel Granados int proc_do_large_bitmap(const struct ctl_table *table, int write, 157532927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1576f461d2dcSChristoph Hellwig { 1577f461d2dcSChristoph Hellwig return -ENOSYS; 1578f461d2dcSChristoph Hellwig } 1579f461d2dcSChristoph Hellwig 1580f461d2dcSChristoph Hellwig #endif /* CONFIG_PROC_SYSCTL */ 1581f461d2dcSChristoph Hellwig 1582f461d2dcSChristoph Hellwig #if defined(CONFIG_SYSCTL) 1583*78eb4ea2SJoel Granados int proc_do_static_key(const struct ctl_table *table, int write, 158432927393SChristoph Hellwig void *buffer, size_t *lenp, loff_t *ppos) 1585f461d2dcSChristoph Hellwig { 1586f461d2dcSChristoph Hellwig struct static_key *key = (struct static_key *)table->data; 1587f461d2dcSChristoph Hellwig static DEFINE_MUTEX(static_key_mutex); 1588f461d2dcSChristoph Hellwig int val, ret; 1589f461d2dcSChristoph Hellwig struct ctl_table tmp = { 1590f461d2dcSChristoph Hellwig .data = &val, 1591f461d2dcSChristoph Hellwig .maxlen = sizeof(val), 1592f461d2dcSChristoph Hellwig .mode = table->mode, 1593f461d2dcSChristoph Hellwig .extra1 = SYSCTL_ZERO, 1594f461d2dcSChristoph Hellwig .extra2 = SYSCTL_ONE, 1595f461d2dcSChristoph Hellwig }; 1596f461d2dcSChristoph Hellwig 1597f461d2dcSChristoph Hellwig if (write && !capable(CAP_SYS_ADMIN)) 1598f461d2dcSChristoph Hellwig return -EPERM; 1599f461d2dcSChristoph Hellwig 1600f461d2dcSChristoph Hellwig mutex_lock(&static_key_mutex); 1601f461d2dcSChristoph Hellwig val = static_key_enabled(key); 1602f461d2dcSChristoph Hellwig ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 1603f461d2dcSChristoph Hellwig if (write && !ret) { 1604f461d2dcSChristoph Hellwig if (val) 1605f461d2dcSChristoph Hellwig static_key_enable(key); 1606f461d2dcSChristoph Hellwig else 1607f461d2dcSChristoph Hellwig static_key_disable(key); 1608f461d2dcSChristoph Hellwig } 1609f461d2dcSChristoph Hellwig mutex_unlock(&static_key_mutex); 1610f461d2dcSChristoph Hellwig return ret; 1611f461d2dcSChristoph Hellwig } 1612f461d2dcSChristoph Hellwig 1613d8217f07SEric W. Biederman static struct ctl_table kern_table[] = { 16141799e35dSIngo Molnar { 16151da177e4SLinus Torvalds .procname = "panic", 16161da177e4SLinus Torvalds .data = &panic_timeout, 16171da177e4SLinus Torvalds .maxlen = sizeof(int), 16181da177e4SLinus Torvalds .mode = 0644, 16196d456111SEric W. Biederman .proc_handler = proc_dointvec, 16201da177e4SLinus Torvalds }, 162134f5a398STheodore Ts'o #ifdef CONFIG_PROC_SYSCTL 16221da177e4SLinus Torvalds { 16231da177e4SLinus Torvalds .procname = "tainted", 162425ddbb18SAndi Kleen .maxlen = sizeof(long), 162534f5a398STheodore Ts'o .mode = 0644, 16266d456111SEric W. Biederman .proc_handler = proc_taint, 16271da177e4SLinus Torvalds }, 1628f4aacea2SKees Cook { 1629f4aacea2SKees Cook .procname = "sysctl_writes_strict", 1630f4aacea2SKees Cook .data = &sysctl_writes_strict, 1631f4aacea2SKees Cook .maxlen = sizeof(int), 1632f4aacea2SKees Cook .mode = 0644, 1633f4aacea2SKees Cook .proc_handler = proc_dointvec_minmax, 163478e36f3bSXiaoming Ni .extra1 = SYSCTL_NEG_ONE, 1635eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 1636f4aacea2SKees Cook }, 163734f5a398STheodore Ts'o #endif 163845807a1dSIngo Molnar { 163945807a1dSIngo Molnar .procname = "print-fatal-signals", 164045807a1dSIngo Molnar .data = &print_fatal_signals, 164145807a1dSIngo Molnar .maxlen = sizeof(int), 164245807a1dSIngo Molnar .mode = 0644, 16436d456111SEric W. Biederman .proc_handler = proc_dointvec, 164445807a1dSIngo Molnar }, 164572c57ed5SDavid S. Miller #ifdef CONFIG_SPARC 16461da177e4SLinus Torvalds { 16471da177e4SLinus Torvalds .procname = "reboot-cmd", 16481da177e4SLinus Torvalds .data = reboot_command, 16491da177e4SLinus Torvalds .maxlen = 256, 16501da177e4SLinus Torvalds .mode = 0644, 16516d456111SEric W. Biederman .proc_handler = proc_dostring, 16521da177e4SLinus Torvalds }, 16531da177e4SLinus Torvalds { 16541da177e4SLinus Torvalds .procname = "stop-a", 16551da177e4SLinus Torvalds .data = &stop_a_enabled, 16561da177e4SLinus Torvalds .maxlen = sizeof (int), 16571da177e4SLinus Torvalds .mode = 0644, 16586d456111SEric W. Biederman .proc_handler = proc_dointvec, 16591da177e4SLinus Torvalds }, 16601da177e4SLinus Torvalds { 16611da177e4SLinus Torvalds .procname = "scons-poweroff", 16621da177e4SLinus Torvalds .data = &scons_pwroff, 16631da177e4SLinus Torvalds .maxlen = sizeof (int), 16641da177e4SLinus Torvalds .mode = 0644, 16656d456111SEric W. Biederman .proc_handler = proc_dointvec, 16661da177e4SLinus Torvalds }, 16671da177e4SLinus Torvalds #endif 16680871420fSDavid S. Miller #ifdef CONFIG_SPARC64 16690871420fSDavid S. Miller { 16700871420fSDavid S. Miller .procname = "tsb-ratio", 16710871420fSDavid S. Miller .data = &sysctl_tsb_ratio, 16720871420fSDavid S. Miller .maxlen = sizeof (int), 16730871420fSDavid S. Miller .mode = 0644, 16746d456111SEric W. Biederman .proc_handler = proc_dointvec, 16750871420fSDavid S. Miller }, 16760871420fSDavid S. Miller #endif 1677b67114dbSHelge Deller #ifdef CONFIG_PARISC 16781da177e4SLinus Torvalds { 16791da177e4SLinus Torvalds .procname = "soft-power", 16801da177e4SLinus Torvalds .data = &pwrsw_enabled, 16811da177e4SLinus Torvalds .maxlen = sizeof (int), 16821da177e4SLinus Torvalds .mode = 0644, 16836d456111SEric W. Biederman .proc_handler = proc_dointvec, 16841da177e4SLinus Torvalds }, 1685bf14e3b9SVineet Gupta #endif 1686bf14e3b9SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW 16871da177e4SLinus Torvalds { 16881da177e4SLinus Torvalds .procname = "unaligned-trap", 16891da177e4SLinus Torvalds .data = &unaligned_enabled, 16901da177e4SLinus Torvalds .maxlen = sizeof (int), 16911da177e4SLinus Torvalds .mode = 0644, 16926d456111SEric W. Biederman .proc_handler = proc_dointvec, 16931da177e4SLinus Torvalds }, 16941da177e4SLinus Torvalds #endif 1695f38f1d2aSSteven Rostedt #ifdef CONFIG_STACK_TRACER 1696f38f1d2aSSteven Rostedt { 1697f38f1d2aSSteven Rostedt .procname = "stack_tracer_enabled", 1698f38f1d2aSSteven Rostedt .data = &stack_tracer_enabled, 1699f38f1d2aSSteven Rostedt .maxlen = sizeof(int), 1700f38f1d2aSSteven Rostedt .mode = 0644, 17016d456111SEric W. Biederman .proc_handler = stack_trace_sysctl, 1702f38f1d2aSSteven Rostedt }, 1703f38f1d2aSSteven Rostedt #endif 1704944ac425SSteven Rostedt #ifdef CONFIG_TRACING 1705944ac425SSteven Rostedt { 17063299b4ddSPeter Zijlstra .procname = "ftrace_dump_on_oops", 1707944ac425SSteven Rostedt .data = &ftrace_dump_on_oops, 170819f0423fSHuang Yiwei .maxlen = MAX_TRACER_SIZE, 1709944ac425SSteven Rostedt .mode = 0644, 171019f0423fSHuang Yiwei .proc_handler = proc_dostring, 1711944ac425SSteven Rostedt }, 1712de7edd31SSteven Rostedt (Red Hat) { 1713de7edd31SSteven Rostedt (Red Hat) .procname = "traceoff_on_warning", 1714de7edd31SSteven Rostedt (Red Hat) .data = &__disable_trace_on_warning, 1715de7edd31SSteven Rostedt (Red Hat) .maxlen = sizeof(__disable_trace_on_warning), 1716de7edd31SSteven Rostedt (Red Hat) .mode = 0644, 1717de7edd31SSteven Rostedt (Red Hat) .proc_handler = proc_dointvec, 1718de7edd31SSteven Rostedt (Red Hat) }, 17190daa2302SSteven Rostedt (Red Hat) { 17200daa2302SSteven Rostedt (Red Hat) .procname = "tracepoint_printk", 17210daa2302SSteven Rostedt (Red Hat) .data = &tracepoint_printk, 17220daa2302SSteven Rostedt (Red Hat) .maxlen = sizeof(tracepoint_printk), 17230daa2302SSteven Rostedt (Red Hat) .mode = 0644, 172442391745SSteven Rostedt (Red Hat) .proc_handler = tracepoint_printk_sysctl, 17250daa2302SSteven Rostedt (Red Hat) }, 1726944ac425SSteven Rostedt #endif 1727a1ef5adbSJohannes Berg #ifdef CONFIG_MODULES 17281da177e4SLinus Torvalds { 17291da177e4SLinus Torvalds .procname = "modprobe", 17301da177e4SLinus Torvalds .data = &modprobe_path, 17311da177e4SLinus Torvalds .maxlen = KMOD_PATH_LEN, 17321da177e4SLinus Torvalds .mode = 0644, 17336d456111SEric W. Biederman .proc_handler = proc_dostring, 17341da177e4SLinus Torvalds }, 17353d43321bSKees Cook { 17363d43321bSKees Cook .procname = "modules_disabled", 17373d43321bSKees Cook .data = &modules_disabled, 17383d43321bSKees Cook .maxlen = sizeof(int), 17393d43321bSKees Cook .mode = 0644, 17403d43321bSKees Cook /* only handle a transition from default "0" to "1" */ 17416d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 1742eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 1743eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 17443d43321bSKees Cook }, 17451da177e4SLinus Torvalds #endif 174686d56134SMichael Marineau #ifdef CONFIG_UEVENT_HELPER 17471da177e4SLinus Torvalds { 17481da177e4SLinus Torvalds .procname = "hotplug", 1749312c004dSKay Sievers .data = &uevent_helper, 1750312c004dSKay Sievers .maxlen = UEVENT_HELPER_PATH_LEN, 17511da177e4SLinus Torvalds .mode = 0644, 17526d456111SEric W. Biederman .proc_handler = proc_dostring, 17531da177e4SLinus Torvalds }, 175486d56134SMichael Marineau #endif 17551da177e4SLinus Torvalds #ifdef CONFIG_MAGIC_SYSRQ 17561da177e4SLinus Torvalds { 17571da177e4SLinus Torvalds .procname = "sysrq", 1758eaee4172SDmitry Safonov .data = NULL, 17591da177e4SLinus Torvalds .maxlen = sizeof (int), 17601da177e4SLinus Torvalds .mode = 0644, 176197f5f0cdSDmitry Torokhov .proc_handler = sysrq_sysctl_handler, 17621da177e4SLinus Torvalds }, 17631da177e4SLinus Torvalds #endif 1764d6f8ff73SRandy Dunlap #ifdef CONFIG_PROC_SYSCTL 17651da177e4SLinus Torvalds { 17661da177e4SLinus Torvalds .procname = "cad_pid", 17679ec52099SCedric Le Goater .data = NULL, 17681da177e4SLinus Torvalds .maxlen = sizeof (int), 17691da177e4SLinus Torvalds .mode = 0600, 17706d456111SEric W. Biederman .proc_handler = proc_do_cad_pid, 17711da177e4SLinus Torvalds }, 1772d6f8ff73SRandy Dunlap #endif 17731da177e4SLinus Torvalds { 17741da177e4SLinus Torvalds .procname = "threads-max", 177516db3d3fSHeinrich Schuchardt .data = NULL, 17761da177e4SLinus Torvalds .maxlen = sizeof(int), 17771da177e4SLinus Torvalds .mode = 0644, 177816db3d3fSHeinrich Schuchardt .proc_handler = sysctl_max_threads, 17791da177e4SLinus Torvalds }, 17801da177e4SLinus Torvalds { 17811da177e4SLinus Torvalds .procname = "overflowuid", 17821da177e4SLinus Torvalds .data = &overflowuid, 17831da177e4SLinus Torvalds .maxlen = sizeof(int), 17841da177e4SLinus Torvalds .mode = 0644, 17856d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 17862452dcb9SXiaoming Ni .extra1 = SYSCTL_ZERO, 178754771613SLuis Chamberlain .extra2 = SYSCTL_MAXOLDUID, 17881da177e4SLinus Torvalds }, 17891da177e4SLinus Torvalds { 17901da177e4SLinus Torvalds .procname = "overflowgid", 17911da177e4SLinus Torvalds .data = &overflowgid, 17921da177e4SLinus Torvalds .maxlen = sizeof(int), 17931da177e4SLinus Torvalds .mode = 0644, 17946d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 17952452dcb9SXiaoming Ni .extra1 = SYSCTL_ZERO, 179654771613SLuis Chamberlain .extra2 = SYSCTL_MAXOLDUID, 17971da177e4SLinus Torvalds }, 1798347a8dc3SMartin Schwidefsky #ifdef CONFIG_S390 17991da177e4SLinus Torvalds { 18001da177e4SLinus Torvalds .procname = "userprocess_debug", 1801ab3c68eeSHeiko Carstens .data = &show_unhandled_signals, 18021da177e4SLinus Torvalds .maxlen = sizeof(int), 18031da177e4SLinus Torvalds .mode = 0644, 18046d456111SEric W. Biederman .proc_handler = proc_dointvec, 18051da177e4SLinus Torvalds }, 18061da177e4SLinus Torvalds #endif 18071da177e4SLinus Torvalds { 18081da177e4SLinus Torvalds .procname = "pid_max", 18091da177e4SLinus Torvalds .data = &pid_max, 18101da177e4SLinus Torvalds .maxlen = sizeof (int), 18111da177e4SLinus Torvalds .mode = 0644, 18126d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 18131da177e4SLinus Torvalds .extra1 = &pid_max_min, 18141da177e4SLinus Torvalds .extra2 = &pid_max_max, 18151da177e4SLinus Torvalds }, 18161da177e4SLinus Torvalds { 18171da177e4SLinus Torvalds .procname = "panic_on_oops", 18181da177e4SLinus Torvalds .data = &panic_on_oops, 18191da177e4SLinus Torvalds .maxlen = sizeof(int), 18201da177e4SLinus Torvalds .mode = 0644, 18216d456111SEric W. Biederman .proc_handler = proc_dointvec, 18221da177e4SLinus Torvalds }, 182381c9d43fSFeng Tang { 182481c9d43fSFeng Tang .procname = "panic_print", 182581c9d43fSFeng Tang .data = &panic_print, 182681c9d43fSFeng Tang .maxlen = sizeof(unsigned long), 182781c9d43fSFeng Tang .mode = 0644, 182881c9d43fSFeng Tang .proc_handler = proc_doulongvec_minmax, 182981c9d43fSFeng Tang }, 1830eaf06b24SDan Rosenberg { 18311da177e4SLinus Torvalds .procname = "ngroups_max", 1832f628867dSStephen Kitt .data = (void *)&ngroups_max, 18331da177e4SLinus Torvalds .maxlen = sizeof (int), 18341da177e4SLinus Torvalds .mode = 0444, 18356d456111SEric W. Biederman .proc_handler = proc_dointvec, 18361da177e4SLinus Torvalds }, 183773efc039SDan Ballard { 183873efc039SDan Ballard .procname = "cap_last_cap", 183973efc039SDan Ballard .data = (void *)&cap_last_cap, 184073efc039SDan Ballard .maxlen = sizeof(int), 184173efc039SDan Ballard .mode = 0444, 184273efc039SDan Ballard .proc_handler = proc_dointvec, 184373efc039SDan Ballard }, 18445dc30558SDon Zickus #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 18455dc30558SDon Zickus { 18465dc30558SDon Zickus .procname = "unknown_nmi_panic", 18475dc30558SDon Zickus .data = &unknown_nmi_panic, 18485dc30558SDon Zickus .maxlen = sizeof (int), 18495dc30558SDon Zickus .mode = 0644, 18505dc30558SDon Zickus .proc_handler = proc_dointvec, 18515dc30558SDon Zickus }, 1852504d7cf1SDon Zickus #endif 1853b6522fa4SXiaoming Ni 1854b6522fa4SXiaoming Ni #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \ 1855b6522fa4SXiaoming Ni defined(CONFIG_DEBUG_STACKOVERFLOW) 1856b6522fa4SXiaoming Ni { 1857b6522fa4SXiaoming Ni .procname = "panic_on_stackoverflow", 1858b6522fa4SXiaoming Ni .data = &sysctl_panic_on_stackoverflow, 1859b6522fa4SXiaoming Ni .maxlen = sizeof(int), 1860b6522fa4SXiaoming Ni .mode = 0644, 1861b6522fa4SXiaoming Ni .proc_handler = proc_dointvec, 1862b6522fa4SXiaoming Ni }, 1863b6522fa4SXiaoming Ni #endif 18641da177e4SLinus Torvalds #if defined(CONFIG_X86) 18651da177e4SLinus Torvalds { 18668da5addaSDon Zickus .procname = "panic_on_unrecovered_nmi", 18678da5addaSDon Zickus .data = &panic_on_unrecovered_nmi, 18688da5addaSDon Zickus .maxlen = sizeof(int), 18698da5addaSDon Zickus .mode = 0644, 18706d456111SEric W. Biederman .proc_handler = proc_dointvec, 18718da5addaSDon Zickus }, 18728da5addaSDon Zickus { 18735211a242SKurt Garloff .procname = "panic_on_io_nmi", 18745211a242SKurt Garloff .data = &panic_on_io_nmi, 18755211a242SKurt Garloff .maxlen = sizeof(int), 18765211a242SKurt Garloff .mode = 0644, 18776d456111SEric W. Biederman .proc_handler = proc_dointvec, 18785211a242SKurt Garloff }, 18795211a242SKurt Garloff { 18801da177e4SLinus Torvalds .procname = "bootloader_type", 18811da177e4SLinus Torvalds .data = &bootloader_type, 18821da177e4SLinus Torvalds .maxlen = sizeof (int), 18831da177e4SLinus Torvalds .mode = 0444, 18846d456111SEric W. Biederman .proc_handler = proc_dointvec, 18851da177e4SLinus Torvalds }, 18860741f4d2SChuck Ebbert { 18875031296cSH. Peter Anvin .procname = "bootloader_version", 18885031296cSH. Peter Anvin .data = &bootloader_version, 18895031296cSH. Peter Anvin .maxlen = sizeof (int), 18905031296cSH. Peter Anvin .mode = 0444, 18916d456111SEric W. Biederman .proc_handler = proc_dointvec, 18925031296cSH. Peter Anvin }, 18935031296cSH. Peter Anvin { 18946e7c4025SIngo Molnar .procname = "io_delay_type", 18956e7c4025SIngo Molnar .data = &io_delay_type, 18966e7c4025SIngo Molnar .maxlen = sizeof(int), 18976e7c4025SIngo Molnar .mode = 0644, 18986d456111SEric W. Biederman .proc_handler = proc_dointvec, 18996e7c4025SIngo Molnar }, 19001da177e4SLinus Torvalds #endif 19017a9166e3SLuke Yang #if defined(CONFIG_MMU) 19021da177e4SLinus Torvalds { 19031da177e4SLinus Torvalds .procname = "randomize_va_space", 19041da177e4SLinus Torvalds .data = &randomize_va_space, 19051da177e4SLinus Torvalds .maxlen = sizeof(int), 19061da177e4SLinus Torvalds .mode = 0644, 19076d456111SEric W. Biederman .proc_handler = proc_dointvec, 19081da177e4SLinus Torvalds }, 19097a9166e3SLuke Yang #endif 19100152fb37SMartin Schwidefsky #if defined(CONFIG_S390) && defined(CONFIG_SMP) 1911951f22d5SMartin Schwidefsky { 1912951f22d5SMartin Schwidefsky .procname = "spin_retry", 1913951f22d5SMartin Schwidefsky .data = &spin_retry, 1914951f22d5SMartin Schwidefsky .maxlen = sizeof (int), 1915951f22d5SMartin Schwidefsky .mode = 0644, 19166d456111SEric W. Biederman .proc_handler = proc_dointvec, 1917951f22d5SMartin Schwidefsky }, 1918951f22d5SMartin Schwidefsky #endif 1919673d5b43SLen Brown #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 1920c255d844SPavel Machek { 1921c255d844SPavel Machek .procname = "acpi_video_flags", 192277afcf78SPavel Machek .data = &acpi_realmode_flags, 1923c255d844SPavel Machek .maxlen = sizeof (unsigned long), 1924c255d844SPavel Machek .mode = 0644, 19256d456111SEric W. Biederman .proc_handler = proc_doulongvec_minmax, 1926c255d844SPavel Machek }, 1927c255d844SPavel Machek #endif 1928b6fca725SVineet Gupta #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN 1929d2b176edSJes Sorensen { 1930d2b176edSJes Sorensen .procname = "ignore-unaligned-usertrap", 1931d2b176edSJes Sorensen .data = &no_unaligned_warning, 1932d2b176edSJes Sorensen .maxlen = sizeof (int), 1933d2b176edSJes Sorensen .mode = 0644, 19346d456111SEric W. Biederman .proc_handler = proc_dointvec, 1935d2b176edSJes Sorensen }, 1936b6fca725SVineet Gupta #endif 193723f78d4aSIngo Molnar #ifdef CONFIG_RT_MUTEXES 193823f78d4aSIngo Molnar { 193923f78d4aSIngo Molnar .procname = "max_lock_depth", 194023f78d4aSIngo Molnar .data = &max_lock_depth, 194123f78d4aSIngo Molnar .maxlen = sizeof(int), 194223f78d4aSIngo Molnar .mode = 0644, 19436d456111SEric W. Biederman .proc_handler = proc_dointvec, 194423f78d4aSIngo Molnar }, 194523f78d4aSIngo Molnar #endif 1946cdd6c482SIngo Molnar #ifdef CONFIG_PERF_EVENTS 1947aa4a2218SVince Weaver /* 1948aa4a2218SVince Weaver * User-space scripts rely on the existence of this file 1949aa4a2218SVince Weaver * as a feature check for perf_events being enabled. 1950aa4a2218SVince Weaver * 1951aa4a2218SVince Weaver * So it's an ABI, do not remove! 1952aa4a2218SVince Weaver */ 19531ccd1549SPeter Zijlstra { 1954cdd6c482SIngo Molnar .procname = "perf_event_paranoid", 1955cdd6c482SIngo Molnar .data = &sysctl_perf_event_paranoid, 1956cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_paranoid), 19571ccd1549SPeter Zijlstra .mode = 0644, 19586d456111SEric W. Biederman .proc_handler = proc_dointvec, 19591ccd1549SPeter Zijlstra }, 1960c5078f78SPeter Zijlstra { 1961cdd6c482SIngo Molnar .procname = "perf_event_mlock_kb", 1962cdd6c482SIngo Molnar .data = &sysctl_perf_event_mlock, 1963cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_mlock), 1964c5078f78SPeter Zijlstra .mode = 0644, 19656d456111SEric W. Biederman .proc_handler = proc_dointvec, 1966c5078f78SPeter Zijlstra }, 1967a78ac325SPeter Zijlstra { 1968cdd6c482SIngo Molnar .procname = "perf_event_max_sample_rate", 1969cdd6c482SIngo Molnar .data = &sysctl_perf_event_sample_rate, 1970cdd6c482SIngo Molnar .maxlen = sizeof(sysctl_perf_event_sample_rate), 1971a78ac325SPeter Zijlstra .mode = 0644, 1972e6814ec3SXiu Jianfeng .proc_handler = perf_event_max_sample_rate_handler, 1973eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 1974a78ac325SPeter Zijlstra }, 197514c63f17SDave Hansen { 197614c63f17SDave Hansen .procname = "perf_cpu_time_max_percent", 197714c63f17SDave Hansen .data = &sysctl_perf_cpu_time_max_percent, 197814c63f17SDave Hansen .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), 197914c63f17SDave Hansen .mode = 0644, 198014c63f17SDave Hansen .proc_handler = perf_cpu_time_max_percent_handler, 1981eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 198278e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_HUNDRED, 198314c63f17SDave Hansen }, 1984c5dfd78eSArnaldo Carvalho de Melo { 1985c5dfd78eSArnaldo Carvalho de Melo .procname = "perf_event_max_stack", 1986a831100aSArnaldo Carvalho de Melo .data = &sysctl_perf_event_max_stack, 1987c5dfd78eSArnaldo Carvalho de Melo .maxlen = sizeof(sysctl_perf_event_max_stack), 1988c5dfd78eSArnaldo Carvalho de Melo .mode = 0644, 1989c5dfd78eSArnaldo Carvalho de Melo .proc_handler = perf_event_max_stack_handler, 1990eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 1991d73840ecSXiaoming Ni .extra2 = (void *)&six_hundred_forty_kb, 1992c5dfd78eSArnaldo Carvalho de Melo }, 1993c85b0334SArnaldo Carvalho de Melo { 1994c85b0334SArnaldo Carvalho de Melo .procname = "perf_event_max_contexts_per_stack", 1995c85b0334SArnaldo Carvalho de Melo .data = &sysctl_perf_event_max_contexts_per_stack, 1996c85b0334SArnaldo Carvalho de Melo .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), 1997c85b0334SArnaldo Carvalho de Melo .mode = 0644, 1998c85b0334SArnaldo Carvalho de Melo .proc_handler = perf_event_max_stack_handler, 1999eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 200078e36f3bSXiaoming Ni .extra2 = SYSCTL_ONE_THOUSAND, 2001c85b0334SArnaldo Carvalho de Melo }, 20021ccd1549SPeter Zijlstra #endif 20039e3961a0SPrarit Bhargava { 20049e3961a0SPrarit Bhargava .procname = "panic_on_warn", 20059e3961a0SPrarit Bhargava .data = &panic_on_warn, 20069e3961a0SPrarit Bhargava .maxlen = sizeof(int), 20079e3961a0SPrarit Bhargava .mode = 0644, 20089e3961a0SPrarit Bhargava .proc_handler = proc_dointvec_minmax, 2009eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2010eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 20119e3961a0SPrarit Bhargava }, 20127251ceb5SGeert Uytterhoeven #ifdef CONFIG_TREE_RCU 2013088e9d25SDaniel Bristot de Oliveira { 2014088e9d25SDaniel Bristot de Oliveira .procname = "panic_on_rcu_stall", 2015088e9d25SDaniel Bristot de Oliveira .data = &sysctl_panic_on_rcu_stall, 2016088e9d25SDaniel Bristot de Oliveira .maxlen = sizeof(sysctl_panic_on_rcu_stall), 2017088e9d25SDaniel Bristot de Oliveira .mode = 0644, 2018088e9d25SDaniel Bristot de Oliveira .proc_handler = proc_dointvec_minmax, 2019eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2020eec4844fSMatteo Croce .extra2 = SYSCTL_ONE, 2021088e9d25SDaniel Bristot de Oliveira }, 2022dfe56404Schao { 2023dfe56404Schao .procname = "max_rcu_stall_to_panic", 2024dfe56404Schao .data = &sysctl_max_rcu_stall_to_panic, 2025dfe56404Schao .maxlen = sizeof(sysctl_max_rcu_stall_to_panic), 2026dfe56404Schao .mode = 0644, 2027dfe56404Schao .proc_handler = proc_dointvec_minmax, 2028dfe56404Schao .extra1 = SYSCTL_ONE, 2029dfe56404Schao .extra2 = SYSCTL_INT_MAX, 2030dfe56404Schao }, 2031dfe56404Schao #endif 20321da177e4SLinus Torvalds }; 20331da177e4SLinus Torvalds 2034d8217f07SEric W. Biederman static struct ctl_table vm_table[] = { 20351da177e4SLinus Torvalds { 20361da177e4SLinus Torvalds .procname = "overcommit_memory", 20371da177e4SLinus Torvalds .data = &sysctl_overcommit_memory, 20381da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_memory), 20391da177e4SLinus Torvalds .mode = 0644, 204056f3547bSFeng Tang .proc_handler = overcommit_policy_handler, 2041eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 204278e36f3bSXiaoming Ni .extra2 = SYSCTL_TWO, 20431da177e4SLinus Torvalds }, 20441da177e4SLinus Torvalds { 20451da177e4SLinus Torvalds .procname = "overcommit_ratio", 20461da177e4SLinus Torvalds .data = &sysctl_overcommit_ratio, 20471da177e4SLinus Torvalds .maxlen = sizeof(sysctl_overcommit_ratio), 20481da177e4SLinus Torvalds .mode = 0644, 204949f0ce5fSJerome Marchand .proc_handler = overcommit_ratio_handler, 205049f0ce5fSJerome Marchand }, 205149f0ce5fSJerome Marchand { 205249f0ce5fSJerome Marchand .procname = "overcommit_kbytes", 205349f0ce5fSJerome Marchand .data = &sysctl_overcommit_kbytes, 205449f0ce5fSJerome Marchand .maxlen = sizeof(sysctl_overcommit_kbytes), 205549f0ce5fSJerome Marchand .mode = 0644, 205649f0ce5fSJerome Marchand .proc_handler = overcommit_kbytes_handler, 20571da177e4SLinus Torvalds }, 20581da177e4SLinus Torvalds { 20591da177e4SLinus Torvalds .procname = "page-cluster", 20601da177e4SLinus Torvalds .data = &page_cluster, 20611da177e4SLinus Torvalds .maxlen = sizeof(int), 20621da177e4SLinus Torvalds .mode = 0644, 2063cb16e95fSPetr Holasek .proc_handler = proc_dointvec_minmax, 2064eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2065ea0ffd0cSKairui Song .extra2 = (void *)&page_cluster_max, 20661da177e4SLinus Torvalds }, 20671da177e4SLinus Torvalds { 20681efff914STheodore Ts'o .procname = "dirtytime_expire_seconds", 20691efff914STheodore Ts'o .data = &dirtytime_expire_interval, 20702d87b309SRandy Dunlap .maxlen = sizeof(dirtytime_expire_interval), 20711efff914STheodore Ts'o .mode = 0644, 20721efff914STheodore Ts'o .proc_handler = dirtytime_interval_handler, 2073eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 20741efff914STheodore Ts'o }, 20751efff914STheodore Ts'o { 20761da177e4SLinus Torvalds .procname = "swappiness", 20771da177e4SLinus Torvalds .data = &vm_swappiness, 20781da177e4SLinus Torvalds .maxlen = sizeof(vm_swappiness), 20791da177e4SLinus Torvalds .mode = 0644, 20806d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2081eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 208278e36f3bSXiaoming Ni .extra2 = SYSCTL_TWO_HUNDRED, 20831da177e4SLinus Torvalds }, 208443b5240cSMuchun Song #ifdef CONFIG_NUMA 208543b5240cSMuchun Song { 208643b5240cSMuchun Song .procname = "numa_stat", 208743b5240cSMuchun Song .data = &sysctl_vm_numa_stat, 208843b5240cSMuchun Song .maxlen = sizeof(int), 208943b5240cSMuchun Song .mode = 0644, 209043b5240cSMuchun Song .proc_handler = sysctl_vm_numa_stat_handler, 209143b5240cSMuchun Song .extra1 = SYSCTL_ZERO, 209243b5240cSMuchun Song .extra2 = SYSCTL_ONE, 209343b5240cSMuchun Song }, 209443b5240cSMuchun Song #endif 20951da177e4SLinus Torvalds { 20969d0243bcSAndrew Morton .procname = "drop_caches", 20979d0243bcSAndrew Morton .data = &sysctl_drop_caches, 20989d0243bcSAndrew Morton .maxlen = sizeof(int), 2099204cb79aSJohannes Weiner .mode = 0200, 21009d0243bcSAndrew Morton .proc_handler = drop_caches_sysctl_handler, 2101eec4844fSMatteo Croce .extra1 = SYSCTL_ONE, 210278e36f3bSXiaoming Ni .extra2 = SYSCTL_FOUR, 21039d0243bcSAndrew Morton }, 21049d0243bcSAndrew Morton { 21055ef64cc8SLinus Torvalds .procname = "page_lock_unfairness", 21065ef64cc8SLinus Torvalds .data = &sysctl_page_lock_unfairness, 21075ef64cc8SLinus Torvalds .maxlen = sizeof(sysctl_page_lock_unfairness), 21085ef64cc8SLinus Torvalds .mode = 0644, 21095ef64cc8SLinus Torvalds .proc_handler = proc_dointvec_minmax, 21105ef64cc8SLinus Torvalds .extra1 = SYSCTL_ZERO, 21115ef64cc8SLinus Torvalds }, 21121da177e4SLinus Torvalds #ifdef CONFIG_MMU 21131da177e4SLinus Torvalds { 21141da177e4SLinus Torvalds .procname = "max_map_count", 21151da177e4SLinus Torvalds .data = &sysctl_max_map_count, 21161da177e4SLinus Torvalds .maxlen = sizeof(sysctl_max_map_count), 21171da177e4SLinus Torvalds .mode = 0644, 21183e26120cSWANG Cong .proc_handler = proc_dointvec_minmax, 2119eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 21201da177e4SLinus Torvalds }, 2121dd8632a1SPaul Mundt #else 2122dd8632a1SPaul Mundt { 2123dd8632a1SPaul Mundt .procname = "nr_trim_pages", 2124dd8632a1SPaul Mundt .data = &sysctl_nr_trim_pages, 2125dd8632a1SPaul Mundt .maxlen = sizeof(sysctl_nr_trim_pages), 2126dd8632a1SPaul Mundt .mode = 0644, 21276d456111SEric W. Biederman .proc_handler = proc_dointvec_minmax, 2128eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2129dd8632a1SPaul Mundt }, 21301da177e4SLinus Torvalds #endif 21311da177e4SLinus Torvalds { 21321da177e4SLinus Torvalds .procname = "vfs_cache_pressure", 21331da177e4SLinus Torvalds .data = &sysctl_vfs_cache_pressure, 21341da177e4SLinus Torvalds .maxlen = sizeof(sysctl_vfs_cache_pressure), 21351da177e4SLinus Torvalds .mode = 0644, 21363b3376f2SLin Feng .proc_handler = proc_dointvec_minmax, 2137eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 21381da177e4SLinus Torvalds }, 213967f3977fSAlexandre Ghiti #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ 214067f3977fSAlexandre Ghiti defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) 21411da177e4SLinus Torvalds { 21421da177e4SLinus Torvalds .procname = "legacy_va_layout", 21431da177e4SLinus Torvalds .data = &sysctl_legacy_va_layout, 21441da177e4SLinus Torvalds .maxlen = sizeof(sysctl_legacy_va_layout), 21451da177e4SLinus Torvalds .mode = 0644, 21463b3376f2SLin Feng .proc_handler = proc_dointvec_minmax, 2147eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 21481da177e4SLinus Torvalds }, 21491da177e4SLinus Torvalds #endif 21501743660bSChristoph Lameter #ifdef CONFIG_NUMA 21511743660bSChristoph Lameter { 21521743660bSChristoph Lameter .procname = "zone_reclaim_mode", 2153a5f5f91dSMel Gorman .data = &node_reclaim_mode, 2154a5f5f91dSMel Gorman .maxlen = sizeof(node_reclaim_mode), 21551743660bSChristoph Lameter .mode = 0644, 21563b3376f2SLin Feng .proc_handler = proc_dointvec_minmax, 2157eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 21581743660bSChristoph Lameter }, 21591743660bSChristoph Lameter #endif 216077461ab3SChristoph Lameter #ifdef CONFIG_SMP 216177461ab3SChristoph Lameter { 216277461ab3SChristoph Lameter .procname = "stat_interval", 216377461ab3SChristoph Lameter .data = &sysctl_stat_interval, 216477461ab3SChristoph Lameter .maxlen = sizeof(sysctl_stat_interval), 216577461ab3SChristoph Lameter .mode = 0644, 21666d456111SEric W. Biederman .proc_handler = proc_dointvec_jiffies, 216777461ab3SChristoph Lameter }, 216852b6f46bSHugh Dickins { 216952b6f46bSHugh Dickins .procname = "stat_refresh", 217052b6f46bSHugh Dickins .data = NULL, 217152b6f46bSHugh Dickins .maxlen = 0, 217252b6f46bSHugh Dickins .mode = 0600, 217352b6f46bSHugh Dickins .proc_handler = vmstat_refresh, 217452b6f46bSHugh Dickins }, 217577461ab3SChristoph Lameter #endif 21766e141546SDavid Howells #ifdef CONFIG_MMU 2177ed032189SEric Paris { 2178ed032189SEric Paris .procname = "mmap_min_addr", 2179788084abSEric Paris .data = &dac_mmap_min_addr, 2180ed032189SEric Paris .maxlen = sizeof(unsigned long), 2181ed032189SEric Paris .mode = 0644, 21826d456111SEric W. Biederman .proc_handler = mmap_min_addr_handler, 2183ed032189SEric Paris }, 21846e141546SDavid Howells #endif 21852b8232ceSAl Viro #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 21865c36e657SPaul Mundt (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 2187e6e5494cSIngo Molnar { 2188e6e5494cSIngo Molnar .procname = "vdso_enabled", 21893d7ee969SAndy Lutomirski #ifdef CONFIG_X86_32 21903d7ee969SAndy Lutomirski .data = &vdso32_enabled, 21913d7ee969SAndy Lutomirski .maxlen = sizeof(vdso32_enabled), 21923d7ee969SAndy Lutomirski #else 2193e6e5494cSIngo Molnar .data = &vdso_enabled, 2194e6e5494cSIngo Molnar .maxlen = sizeof(vdso_enabled), 21953d7ee969SAndy Lutomirski #endif 2196e6e5494cSIngo Molnar .mode = 0644, 21976d456111SEric W. Biederman .proc_handler = proc_dointvec, 2198eec4844fSMatteo Croce .extra1 = SYSCTL_ZERO, 2199e6e5494cSIngo Molnar }, 2200e6e5494cSIngo Molnar #endif 2201c9b1d098SAndrew Shewmaker { 2202c9b1d098SAndrew Shewmaker .procname = "user_reserve_kbytes", 2203c9b1d098SAndrew Shewmaker .data = &sysctl_user_reserve_kbytes, 2204c9b1d098SAndrew Shewmaker .maxlen = sizeof(sysctl_user_reserve_kbytes), 2205c9b1d098SAndrew Shewmaker .mode = 0644, 2206c9b1d098SAndrew Shewmaker .proc_handler = proc_doulongvec_minmax, 2207c9b1d098SAndrew Shewmaker }, 22084eeab4f5SAndrew Shewmaker { 22094eeab4f5SAndrew Shewmaker .procname = "admin_reserve_kbytes", 22104eeab4f5SAndrew Shewmaker .data = &sysctl_admin_reserve_kbytes, 22114eeab4f5SAndrew Shewmaker .maxlen = sizeof(sysctl_admin_reserve_kbytes), 22124eeab4f5SAndrew Shewmaker .mode = 0644, 22134eeab4f5SAndrew Shewmaker .proc_handler = proc_doulongvec_minmax, 22144eeab4f5SAndrew Shewmaker }, 2215d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS 2216d07e2259SDaniel Cashman { 2217d07e2259SDaniel Cashman .procname = "mmap_rnd_bits", 2218d07e2259SDaniel Cashman .data = &mmap_rnd_bits, 2219d07e2259SDaniel Cashman .maxlen = sizeof(mmap_rnd_bits), 2220d07e2259SDaniel Cashman .mode = 0600, 2221d07e2259SDaniel Cashman .proc_handler = proc_dointvec_minmax, 2222d07e2259SDaniel Cashman .extra1 = (void *)&mmap_rnd_bits_min, 2223d07e2259SDaniel Cashman .extra2 = (void *)&mmap_rnd_bits_max, 2224d07e2259SDaniel Cashman }, 2225d07e2259SDaniel Cashman #endif 2226d07e2259SDaniel Cashman #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS 2227d07e2259SDaniel Cashman { 2228d07e2259SDaniel Cashman .procname = "mmap_rnd_compat_bits", 2229d07e2259SDaniel Cashman .data = &mmap_rnd_compat_bits, 2230d07e2259SDaniel Cashman .maxlen = sizeof(mmap_rnd_compat_bits), 2231d07e2259SDaniel Cashman .mode = 0600, 2232d07e2259SDaniel Cashman .proc_handler = proc_dointvec_minmax, 2233d07e2259SDaniel Cashman .extra1 = (void *)&mmap_rnd_compat_bits_min, 2234d07e2259SDaniel Cashman .extra2 = (void *)&mmap_rnd_compat_bits_max, 2235d07e2259SDaniel Cashman }, 2236d07e2259SDaniel Cashman #endif 22371da177e4SLinus Torvalds }; 22381da177e4SLinus Torvalds 2239d8c0418aSLuis Chamberlain int __init sysctl_init_bases(void) 2240330d57fbSAl Viro { 22412f5edd03SJoel Granados register_sysctl_init("kernel", kern_table); 22422f5edd03SJoel Granados register_sysctl_init("vm", vm_table); 2243fd4b616bSSteven Rostedt 2244330d57fbSAl Viro return 0; 2245f7e6ced4SAl Viro } 2246b89a8171SEric W. Biederman #endif /* CONFIG_SYSCTL */ 22471da177e4SLinus Torvalds /* 22481da177e4SLinus Torvalds * No sense putting this after each symbol definition, twice, 22491da177e4SLinus Torvalds * exception granted :-) 22501da177e4SLinus Torvalds */ 2251a2071573SJia He EXPORT_SYMBOL(proc_dobool); 22521da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec); 2253e7d316a0SSubash Abhinov Kasiviswanathan EXPORT_SYMBOL(proc_douintvec); 22541da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_jiffies); 22551da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_minmax); 225661d9b56aSLuis R. Rodriguez EXPORT_SYMBOL_GPL(proc_douintvec_minmax); 22571da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 22581da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 22591da177e4SLinus Torvalds EXPORT_SYMBOL(proc_dostring); 22601da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_minmax); 22611da177e4SLinus Torvalds EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 22620bc19985SStephen Suryaputra EXPORT_SYMBOL(proc_do_large_bitmap); 2263