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