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