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/mm.h> 24 #include <linux/swap.h> 25 #include <linux/slab.h> 26 #include <linux/sysctl.h> 27 #include <linux/bitmap.h> 28 #include <linux/signal.h> 29 #include <linux/panic.h> 30 #include <linux/printk.h> 31 #include <linux/proc_fs.h> 32 #include <linux/security.h> 33 #include <linux/ctype.h> 34 #include <linux/kmemleak.h> 35 #include <linux/filter.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/syscalls.h> 53 #include <linux/vmstat.h> 54 #include <linux/nfs_fs.h> 55 #include <linux/acpi.h> 56 #include <linux/reboot.h> 57 #include <linux/ftrace.h> 58 #include <linux/perf_event.h> 59 #include <linux/oom.h> 60 #include <linux/kmod.h> 61 #include <linux/capability.h> 62 #include <linux/binfmts.h> 63 #include <linux/sched/sysctl.h> 64 #include <linux/mount.h> 65 #include <linux/userfaultfd_k.h> 66 #include <linux/pid.h> 67 68 #include "../lib/kstrtox.h" 69 70 #include <linux/uaccess.h> 71 #include <asm/processor.h> 72 73 #ifdef CONFIG_X86 74 #include <asm/nmi.h> 75 #include <asm/stacktrace.h> 76 #include <asm/io.h> 77 #endif 78 #ifdef CONFIG_SPARC 79 #include <asm/setup.h> 80 #endif 81 #ifdef CONFIG_RT_MUTEXES 82 #include <linux/rtmutex.h> 83 #endif 84 85 #if defined(CONFIG_SYSCTL) 86 87 /* Constants used for minimum and maximum */ 88 89 #ifdef CONFIG_PERF_EVENTS 90 static const int six_hundred_forty_kb = 640 * 1024; 91 #endif 92 93 94 static const int ngroups_max = NGROUPS_MAX; 95 static const int cap_last_cap = CAP_LAST_CAP; 96 97 #ifdef CONFIG_PROC_SYSCTL 98 99 /** 100 * enum sysctl_writes_mode - supported sysctl write modes 101 * 102 * @SYSCTL_WRITES_LEGACY: each write syscall must fully contain the sysctl value 103 * to be written, and multiple writes on the same sysctl file descriptor 104 * will rewrite the sysctl value, regardless of file position. No warning 105 * is issued when the initial position is not 0. 106 * @SYSCTL_WRITES_WARN: same as above but warn when the initial file position is 107 * not 0. 108 * @SYSCTL_WRITES_STRICT: writes to numeric sysctl entries must always be at 109 * file position 0 and the value must be fully contained in the buffer 110 * sent to the write syscall. If dealing with strings respect the file 111 * position, but restrict this to the max length of the buffer, anything 112 * passed the max length will be ignored. Multiple writes will append 113 * to the buffer. 114 * 115 * These write modes control how current file position affects the behavior of 116 * updating sysctl values through the proc interface on each write. 117 */ 118 enum sysctl_writes_mode { 119 SYSCTL_WRITES_LEGACY = -1, 120 SYSCTL_WRITES_WARN = 0, 121 SYSCTL_WRITES_STRICT = 1, 122 }; 123 124 static enum sysctl_writes_mode sysctl_writes_strict = SYSCTL_WRITES_STRICT; 125 #endif /* CONFIG_PROC_SYSCTL */ 126 127 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ 128 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) 129 int sysctl_legacy_va_layout; 130 #endif 131 132 #ifdef CONFIG_COMPACTION 133 /* min_extfrag_threshold is SYSCTL_ZERO */; 134 static const int max_extfrag_threshold = 1000; 135 #endif 136 137 #endif /* CONFIG_SYSCTL */ 138 139 /* 140 * /proc/sys support 141 */ 142 143 #ifdef CONFIG_PROC_SYSCTL 144 145 static int _proc_do_string(char *data, int maxlen, int write, 146 char *buffer, size_t *lenp, loff_t *ppos) 147 { 148 size_t len; 149 char c, *p; 150 151 if (!data || !maxlen || !*lenp) { 152 *lenp = 0; 153 return 0; 154 } 155 156 if (write) { 157 if (sysctl_writes_strict == SYSCTL_WRITES_STRICT) { 158 /* Only continue writes not past the end of buffer. */ 159 len = strlen(data); 160 if (len > maxlen - 1) 161 len = maxlen - 1; 162 163 if (*ppos > len) 164 return 0; 165 len = *ppos; 166 } else { 167 /* Start writing from beginning of buffer. */ 168 len = 0; 169 } 170 171 *ppos += *lenp; 172 p = buffer; 173 while ((p - buffer) < *lenp && len < maxlen - 1) { 174 c = *(p++); 175 if (c == 0 || c == '\n') 176 break; 177 data[len++] = c; 178 } 179 data[len] = 0; 180 } else { 181 len = strlen(data); 182 if (len > maxlen) 183 len = maxlen; 184 185 if (*ppos > len) { 186 *lenp = 0; 187 return 0; 188 } 189 190 data += *ppos; 191 len -= *ppos; 192 193 if (len > *lenp) 194 len = *lenp; 195 if (len) 196 memcpy(buffer, data, len); 197 if (len < *lenp) { 198 buffer[len] = '\n'; 199 len++; 200 } 201 *lenp = len; 202 *ppos += len; 203 } 204 return 0; 205 } 206 207 static void warn_sysctl_write(struct ctl_table *table) 208 { 209 pr_warn_once("%s wrote to %s when file position was not 0!\n" 210 "This will not be supported in the future. To silence this\n" 211 "warning, set kernel.sysctl_writes_strict = -1\n", 212 current->comm, table->procname); 213 } 214 215 /** 216 * proc_first_pos_non_zero_ignore - check if first position is allowed 217 * @ppos: file position 218 * @table: the sysctl table 219 * 220 * Returns true if the first position is non-zero and the sysctl_writes_strict 221 * mode indicates this is not allowed for numeric input types. String proc 222 * handlers can ignore the return value. 223 */ 224 static bool proc_first_pos_non_zero_ignore(loff_t *ppos, 225 struct ctl_table *table) 226 { 227 if (!*ppos) 228 return false; 229 230 switch (sysctl_writes_strict) { 231 case SYSCTL_WRITES_STRICT: 232 return true; 233 case SYSCTL_WRITES_WARN: 234 warn_sysctl_write(table); 235 return false; 236 default: 237 return false; 238 } 239 } 240 241 /** 242 * proc_dostring - read a string sysctl 243 * @table: the sysctl table 244 * @write: %TRUE if this is a write to the sysctl file 245 * @buffer: the user buffer 246 * @lenp: the size of the user buffer 247 * @ppos: file position 248 * 249 * Reads/writes a string from/to the user buffer. If the kernel 250 * buffer provided is not large enough to hold the string, the 251 * string is truncated. The copied string is %NULL-terminated. 252 * If the string is being read by the user process, it is copied 253 * and a newline '\n' is added. It is truncated if the buffer is 254 * not large enough. 255 * 256 * Returns 0 on success. 257 */ 258 int proc_dostring(struct ctl_table *table, int write, 259 void *buffer, size_t *lenp, loff_t *ppos) 260 { 261 if (write) 262 proc_first_pos_non_zero_ignore(ppos, table); 263 264 return _proc_do_string(table->data, table->maxlen, write, buffer, lenp, 265 ppos); 266 } 267 268 static size_t proc_skip_spaces(char **buf) 269 { 270 size_t ret; 271 char *tmp = skip_spaces(*buf); 272 ret = tmp - *buf; 273 *buf = tmp; 274 return ret; 275 } 276 277 static void proc_skip_char(char **buf, size_t *size, const char v) 278 { 279 while (*size) { 280 if (**buf != v) 281 break; 282 (*size)--; 283 (*buf)++; 284 } 285 } 286 287 /** 288 * strtoul_lenient - parse an ASCII formatted integer from a buffer and only 289 * fail on overflow 290 * 291 * @cp: kernel buffer containing the string to parse 292 * @endp: pointer to store the trailing characters 293 * @base: the base to use 294 * @res: where the parsed integer will be stored 295 * 296 * In case of success 0 is returned and @res will contain the parsed integer, 297 * @endp will hold any trailing characters. 298 * This function will fail the parse on overflow. If there wasn't an overflow 299 * the function will defer the decision what characters count as invalid to the 300 * caller. 301 */ 302 static int strtoul_lenient(const char *cp, char **endp, unsigned int base, 303 unsigned long *res) 304 { 305 unsigned long long result; 306 unsigned int rv; 307 308 cp = _parse_integer_fixup_radix(cp, &base); 309 rv = _parse_integer(cp, base, &result); 310 if ((rv & KSTRTOX_OVERFLOW) || (result != (unsigned long)result)) 311 return -ERANGE; 312 313 cp += rv; 314 315 if (endp) 316 *endp = (char *)cp; 317 318 *res = (unsigned long)result; 319 return 0; 320 } 321 322 #define TMPBUFLEN 22 323 /** 324 * proc_get_long - reads an ASCII formatted integer from a user buffer 325 * 326 * @buf: a kernel buffer 327 * @size: size of the kernel buffer 328 * @val: this is where the number will be stored 329 * @neg: set to %TRUE if number is negative 330 * @perm_tr: a vector which contains the allowed trailers 331 * @perm_tr_len: size of the perm_tr vector 332 * @tr: pointer to store the trailer character 333 * 334 * In case of success %0 is returned and @buf and @size are updated with 335 * the amount of bytes read. If @tr is non-NULL and a trailing 336 * character exists (size is non-zero after returning from this 337 * function), @tr is updated with the trailing character. 338 */ 339 static int proc_get_long(char **buf, size_t *size, 340 unsigned long *val, bool *neg, 341 const char *perm_tr, unsigned perm_tr_len, char *tr) 342 { 343 int len; 344 char *p, tmp[TMPBUFLEN]; 345 346 if (!*size) 347 return -EINVAL; 348 349 len = *size; 350 if (len > TMPBUFLEN - 1) 351 len = TMPBUFLEN - 1; 352 353 memcpy(tmp, *buf, len); 354 355 tmp[len] = 0; 356 p = tmp; 357 if (*p == '-' && *size > 1) { 358 *neg = true; 359 p++; 360 } else 361 *neg = false; 362 if (!isdigit(*p)) 363 return -EINVAL; 364 365 if (strtoul_lenient(p, &p, 0, val)) 366 return -EINVAL; 367 368 len = p - tmp; 369 370 /* We don't know if the next char is whitespace thus we may accept 371 * invalid integers (e.g. 1234...a) or two integers instead of one 372 * (e.g. 123...1). So lets not allow such large numbers. */ 373 if (len == TMPBUFLEN - 1) 374 return -EINVAL; 375 376 if (len < *size && perm_tr_len && !memchr(perm_tr, *p, perm_tr_len)) 377 return -EINVAL; 378 379 if (tr && (len < *size)) 380 *tr = *p; 381 382 *buf += len; 383 *size -= len; 384 385 return 0; 386 } 387 388 /** 389 * proc_put_long - converts an integer to a decimal ASCII formatted string 390 * 391 * @buf: the user buffer 392 * @size: the size of the user buffer 393 * @val: the integer to be converted 394 * @neg: sign of the number, %TRUE for negative 395 * 396 * In case of success @buf and @size are updated with the amount of bytes 397 * written. 398 */ 399 static void proc_put_long(void **buf, size_t *size, unsigned long val, bool neg) 400 { 401 int len; 402 char tmp[TMPBUFLEN], *p = tmp; 403 404 sprintf(p, "%s%lu", neg ? "-" : "", val); 405 len = strlen(tmp); 406 if (len > *size) 407 len = *size; 408 memcpy(*buf, tmp, len); 409 *size -= len; 410 *buf += len; 411 } 412 #undef TMPBUFLEN 413 414 static void proc_put_char(void **buf, size_t *size, char c) 415 { 416 if (*size) { 417 char **buffer = (char **)buf; 418 **buffer = c; 419 420 (*size)--; 421 (*buffer)++; 422 *buf = *buffer; 423 } 424 } 425 426 static int do_proc_dobool_conv(bool *negp, unsigned long *lvalp, 427 int *valp, 428 int write, void *data) 429 { 430 if (write) { 431 *(bool *)valp = *lvalp; 432 } else { 433 int val = *(bool *)valp; 434 435 *lvalp = (unsigned long)val; 436 *negp = false; 437 } 438 return 0; 439 } 440 441 static int do_proc_dointvec_conv(bool *negp, unsigned long *lvalp, 442 int *valp, 443 int write, void *data) 444 { 445 if (write) { 446 if (*negp) { 447 if (*lvalp > (unsigned long) INT_MAX + 1) 448 return -EINVAL; 449 WRITE_ONCE(*valp, -*lvalp); 450 } else { 451 if (*lvalp > (unsigned long) INT_MAX) 452 return -EINVAL; 453 WRITE_ONCE(*valp, *lvalp); 454 } 455 } else { 456 int val = READ_ONCE(*valp); 457 if (val < 0) { 458 *negp = true; 459 *lvalp = -(unsigned long)val; 460 } else { 461 *negp = false; 462 *lvalp = (unsigned long)val; 463 } 464 } 465 return 0; 466 } 467 468 static int do_proc_douintvec_conv(unsigned long *lvalp, 469 unsigned int *valp, 470 int write, void *data) 471 { 472 if (write) { 473 if (*lvalp > UINT_MAX) 474 return -EINVAL; 475 WRITE_ONCE(*valp, *lvalp); 476 } else { 477 unsigned int val = READ_ONCE(*valp); 478 *lvalp = (unsigned long)val; 479 } 480 return 0; 481 } 482 483 static const char proc_wspace_sep[] = { ' ', '\t', '\n' }; 484 485 static int __do_proc_dointvec(void *tbl_data, struct ctl_table *table, 486 int write, void *buffer, 487 size_t *lenp, loff_t *ppos, 488 int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 489 int write, void *data), 490 void *data) 491 { 492 int *i, vleft, first = 1, err = 0; 493 size_t left; 494 char *p; 495 496 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 497 *lenp = 0; 498 return 0; 499 } 500 501 i = (int *) tbl_data; 502 vleft = table->maxlen / sizeof(*i); 503 left = *lenp; 504 505 if (!conv) 506 conv = do_proc_dointvec_conv; 507 508 if (write) { 509 if (proc_first_pos_non_zero_ignore(ppos, table)) 510 goto out; 511 512 if (left > PAGE_SIZE - 1) 513 left = PAGE_SIZE - 1; 514 p = buffer; 515 } 516 517 for (; left && vleft--; i++, first=0) { 518 unsigned long lval; 519 bool neg; 520 521 if (write) { 522 left -= proc_skip_spaces(&p); 523 524 if (!left) 525 break; 526 err = proc_get_long(&p, &left, &lval, &neg, 527 proc_wspace_sep, 528 sizeof(proc_wspace_sep), NULL); 529 if (err) 530 break; 531 if (conv(&neg, &lval, i, 1, data)) { 532 err = -EINVAL; 533 break; 534 } 535 } else { 536 if (conv(&neg, &lval, i, 0, data)) { 537 err = -EINVAL; 538 break; 539 } 540 if (!first) 541 proc_put_char(&buffer, &left, '\t'); 542 proc_put_long(&buffer, &left, lval, neg); 543 } 544 } 545 546 if (!write && !first && left && !err) 547 proc_put_char(&buffer, &left, '\n'); 548 if (write && !err && left) 549 left -= proc_skip_spaces(&p); 550 if (write && first) 551 return err ? : -EINVAL; 552 *lenp -= left; 553 out: 554 *ppos += *lenp; 555 return err; 556 } 557 558 static int do_proc_dointvec(struct ctl_table *table, int write, 559 void *buffer, size_t *lenp, loff_t *ppos, 560 int (*conv)(bool *negp, unsigned long *lvalp, int *valp, 561 int write, void *data), 562 void *data) 563 { 564 return __do_proc_dointvec(table->data, table, write, 565 buffer, lenp, ppos, conv, data); 566 } 567 568 static int do_proc_douintvec_w(unsigned int *tbl_data, 569 struct ctl_table *table, 570 void *buffer, 571 size_t *lenp, loff_t *ppos, 572 int (*conv)(unsigned long *lvalp, 573 unsigned int *valp, 574 int write, void *data), 575 void *data) 576 { 577 unsigned long lval; 578 int err = 0; 579 size_t left; 580 bool neg; 581 char *p = buffer; 582 583 left = *lenp; 584 585 if (proc_first_pos_non_zero_ignore(ppos, table)) 586 goto bail_early; 587 588 if (left > PAGE_SIZE - 1) 589 left = PAGE_SIZE - 1; 590 591 left -= proc_skip_spaces(&p); 592 if (!left) { 593 err = -EINVAL; 594 goto out_free; 595 } 596 597 err = proc_get_long(&p, &left, &lval, &neg, 598 proc_wspace_sep, 599 sizeof(proc_wspace_sep), NULL); 600 if (err || neg) { 601 err = -EINVAL; 602 goto out_free; 603 } 604 605 if (conv(&lval, tbl_data, 1, data)) { 606 err = -EINVAL; 607 goto out_free; 608 } 609 610 if (!err && left) 611 left -= proc_skip_spaces(&p); 612 613 out_free: 614 if (err) 615 return -EINVAL; 616 617 return 0; 618 619 /* This is in keeping with old __do_proc_dointvec() */ 620 bail_early: 621 *ppos += *lenp; 622 return err; 623 } 624 625 static int do_proc_douintvec_r(unsigned int *tbl_data, void *buffer, 626 size_t *lenp, loff_t *ppos, 627 int (*conv)(unsigned long *lvalp, 628 unsigned int *valp, 629 int write, void *data), 630 void *data) 631 { 632 unsigned long lval; 633 int err = 0; 634 size_t left; 635 636 left = *lenp; 637 638 if (conv(&lval, tbl_data, 0, data)) { 639 err = -EINVAL; 640 goto out; 641 } 642 643 proc_put_long(&buffer, &left, lval, false); 644 if (!left) 645 goto out; 646 647 proc_put_char(&buffer, &left, '\n'); 648 649 out: 650 *lenp -= left; 651 *ppos += *lenp; 652 653 return err; 654 } 655 656 static int __do_proc_douintvec(void *tbl_data, struct ctl_table *table, 657 int write, void *buffer, 658 size_t *lenp, loff_t *ppos, 659 int (*conv)(unsigned long *lvalp, 660 unsigned int *valp, 661 int write, void *data), 662 void *data) 663 { 664 unsigned int *i, vleft; 665 666 if (!tbl_data || !table->maxlen || !*lenp || (*ppos && !write)) { 667 *lenp = 0; 668 return 0; 669 } 670 671 i = (unsigned int *) tbl_data; 672 vleft = table->maxlen / sizeof(*i); 673 674 /* 675 * Arrays are not supported, keep this simple. *Do not* add 676 * support for them. 677 */ 678 if (vleft != 1) { 679 *lenp = 0; 680 return -EINVAL; 681 } 682 683 if (!conv) 684 conv = do_proc_douintvec_conv; 685 686 if (write) 687 return do_proc_douintvec_w(i, table, buffer, lenp, ppos, 688 conv, data); 689 return do_proc_douintvec_r(i, buffer, lenp, ppos, conv, data); 690 } 691 692 int do_proc_douintvec(struct ctl_table *table, int write, 693 void *buffer, size_t *lenp, loff_t *ppos, 694 int (*conv)(unsigned long *lvalp, 695 unsigned int *valp, 696 int write, void *data), 697 void *data) 698 { 699 return __do_proc_douintvec(table->data, table, write, 700 buffer, lenp, ppos, conv, data); 701 } 702 703 /** 704 * proc_dobool - read/write a bool 705 * @table: the sysctl table 706 * @write: %TRUE if this is a write to the sysctl file 707 * @buffer: the user buffer 708 * @lenp: the size of the user buffer 709 * @ppos: file position 710 * 711 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 712 * values from/to the user buffer, treated as an ASCII string. 713 * 714 * Returns 0 on success. 715 */ 716 int proc_dobool(struct ctl_table *table, int write, void *buffer, 717 size_t *lenp, loff_t *ppos) 718 { 719 return do_proc_dointvec(table, write, buffer, lenp, ppos, 720 do_proc_dobool_conv, NULL); 721 } 722 723 /** 724 * proc_dointvec - read a vector of integers 725 * @table: the sysctl table 726 * @write: %TRUE if this is a write to the sysctl file 727 * @buffer: the user buffer 728 * @lenp: the size of the user buffer 729 * @ppos: file position 730 * 731 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 732 * values from/to the user buffer, treated as an ASCII string. 733 * 734 * Returns 0 on success. 735 */ 736 int proc_dointvec(struct ctl_table *table, int write, void *buffer, 737 size_t *lenp, loff_t *ppos) 738 { 739 return do_proc_dointvec(table, write, buffer, lenp, ppos, NULL, NULL); 740 } 741 742 #ifdef CONFIG_COMPACTION 743 static int proc_dointvec_minmax_warn_RT_change(struct ctl_table *table, 744 int write, void *buffer, size_t *lenp, loff_t *ppos) 745 { 746 int ret, old; 747 748 if (!IS_ENABLED(CONFIG_PREEMPT_RT) || !write) 749 return proc_dointvec_minmax(table, write, buffer, lenp, ppos); 750 751 old = *(int *)table->data; 752 ret = proc_dointvec_minmax(table, write, buffer, lenp, ppos); 753 if (ret) 754 return ret; 755 if (old != *(int *)table->data) 756 pr_warn_once("sysctl attribute %s changed by %s[%d]\n", 757 table->procname, current->comm, 758 task_pid_nr(current)); 759 return ret; 760 } 761 #endif 762 763 /** 764 * proc_douintvec - read a vector of unsigned integers 765 * @table: the sysctl table 766 * @write: %TRUE if this is a write to the sysctl file 767 * @buffer: the user buffer 768 * @lenp: the size of the user buffer 769 * @ppos: file position 770 * 771 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer 772 * values from/to the user buffer, treated as an ASCII string. 773 * 774 * Returns 0 on success. 775 */ 776 int proc_douintvec(struct ctl_table *table, int write, void *buffer, 777 size_t *lenp, loff_t *ppos) 778 { 779 return do_proc_douintvec(table, write, buffer, lenp, ppos, 780 do_proc_douintvec_conv, NULL); 781 } 782 783 /* 784 * Taint values can only be increased 785 * This means we can safely use a temporary. 786 */ 787 static int proc_taint(struct ctl_table *table, int write, 788 void *buffer, size_t *lenp, loff_t *ppos) 789 { 790 struct ctl_table t; 791 unsigned long tmptaint = get_taint(); 792 int err; 793 794 if (write && !capable(CAP_SYS_ADMIN)) 795 return -EPERM; 796 797 t = *table; 798 t.data = &tmptaint; 799 err = proc_doulongvec_minmax(&t, write, buffer, lenp, ppos); 800 if (err < 0) 801 return err; 802 803 if (write) { 804 int i; 805 806 /* 807 * If we are relying on panic_on_taint not producing 808 * false positives due to userspace input, bail out 809 * before setting the requested taint flags. 810 */ 811 if (panic_on_taint_nousertaint && (tmptaint & panic_on_taint)) 812 return -EINVAL; 813 814 /* 815 * Poor man's atomic or. Not worth adding a primitive 816 * to everyone's atomic.h for this 817 */ 818 for (i = 0; i < TAINT_FLAGS_COUNT; i++) 819 if ((1UL << i) & tmptaint) 820 add_taint(i, LOCKDEP_STILL_OK); 821 } 822 823 return err; 824 } 825 826 /** 827 * struct do_proc_dointvec_minmax_conv_param - proc_dointvec_minmax() range checking structure 828 * @min: pointer to minimum allowable value 829 * @max: pointer to maximum allowable value 830 * 831 * The do_proc_dointvec_minmax_conv_param structure provides the 832 * minimum and maximum values for doing range checking for those sysctl 833 * parameters that use the proc_dointvec_minmax() handler. 834 */ 835 struct do_proc_dointvec_minmax_conv_param { 836 int *min; 837 int *max; 838 }; 839 840 static int do_proc_dointvec_minmax_conv(bool *negp, unsigned long *lvalp, 841 int *valp, 842 int write, void *data) 843 { 844 int tmp, ret; 845 struct do_proc_dointvec_minmax_conv_param *param = data; 846 /* 847 * If writing, first do so via a temporary local int so we can 848 * bounds-check it before touching *valp. 849 */ 850 int *ip = write ? &tmp : valp; 851 852 ret = do_proc_dointvec_conv(negp, lvalp, ip, write, data); 853 if (ret) 854 return ret; 855 856 if (write) { 857 if ((param->min && *param->min > tmp) || 858 (param->max && *param->max < tmp)) 859 return -EINVAL; 860 WRITE_ONCE(*valp, tmp); 861 } 862 863 return 0; 864 } 865 866 /** 867 * proc_dointvec_minmax - read a vector of integers with min/max values 868 * @table: the sysctl table 869 * @write: %TRUE if this is a write to the sysctl file 870 * @buffer: the user buffer 871 * @lenp: the size of the user buffer 872 * @ppos: file position 873 * 874 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 875 * values from/to the user buffer, treated as an ASCII string. 876 * 877 * This routine will ensure the values are within the range specified by 878 * table->extra1 (min) and table->extra2 (max). 879 * 880 * Returns 0 on success or -EINVAL on write when the range check fails. 881 */ 882 int proc_dointvec_minmax(struct ctl_table *table, int write, 883 void *buffer, size_t *lenp, loff_t *ppos) 884 { 885 struct do_proc_dointvec_minmax_conv_param param = { 886 .min = (int *) table->extra1, 887 .max = (int *) table->extra2, 888 }; 889 return do_proc_dointvec(table, write, buffer, lenp, ppos, 890 do_proc_dointvec_minmax_conv, ¶m); 891 } 892 893 /** 894 * struct do_proc_douintvec_minmax_conv_param - proc_douintvec_minmax() range checking structure 895 * @min: pointer to minimum allowable value 896 * @max: pointer to maximum allowable value 897 * 898 * The do_proc_douintvec_minmax_conv_param structure provides the 899 * minimum and maximum values for doing range checking for those sysctl 900 * parameters that use the proc_douintvec_minmax() handler. 901 */ 902 struct do_proc_douintvec_minmax_conv_param { 903 unsigned int *min; 904 unsigned int *max; 905 }; 906 907 static int do_proc_douintvec_minmax_conv(unsigned long *lvalp, 908 unsigned int *valp, 909 int write, void *data) 910 { 911 int ret; 912 unsigned int tmp; 913 struct do_proc_douintvec_minmax_conv_param *param = data; 914 /* write via temporary local uint for bounds-checking */ 915 unsigned int *up = write ? &tmp : valp; 916 917 ret = do_proc_douintvec_conv(lvalp, up, write, data); 918 if (ret) 919 return ret; 920 921 if (write) { 922 if ((param->min && *param->min > tmp) || 923 (param->max && *param->max < tmp)) 924 return -ERANGE; 925 926 WRITE_ONCE(*valp, tmp); 927 } 928 929 return 0; 930 } 931 932 /** 933 * proc_douintvec_minmax - read a vector of unsigned ints with min/max values 934 * @table: the sysctl table 935 * @write: %TRUE if this is a write to the sysctl file 936 * @buffer: the user buffer 937 * @lenp: the size of the user buffer 938 * @ppos: file position 939 * 940 * Reads/writes up to table->maxlen/sizeof(unsigned int) unsigned integer 941 * values from/to the user buffer, treated as an ASCII string. Negative 942 * strings are not allowed. 943 * 944 * This routine will ensure the values are within the range specified by 945 * table->extra1 (min) and table->extra2 (max). There is a final sanity 946 * check for UINT_MAX to avoid having to support wrap around uses from 947 * userspace. 948 * 949 * Returns 0 on success or -ERANGE on write when the range check fails. 950 */ 951 int proc_douintvec_minmax(struct ctl_table *table, int write, 952 void *buffer, size_t *lenp, loff_t *ppos) 953 { 954 struct do_proc_douintvec_minmax_conv_param param = { 955 .min = (unsigned int *) table->extra1, 956 .max = (unsigned int *) table->extra2, 957 }; 958 return do_proc_douintvec(table, write, buffer, lenp, ppos, 959 do_proc_douintvec_minmax_conv, ¶m); 960 } 961 962 /** 963 * proc_dou8vec_minmax - read a vector of unsigned chars with min/max values 964 * @table: the sysctl table 965 * @write: %TRUE if this is a write to the sysctl file 966 * @buffer: the user buffer 967 * @lenp: the size of the user buffer 968 * @ppos: file position 969 * 970 * Reads/writes up to table->maxlen/sizeof(u8) unsigned chars 971 * values from/to the user buffer, treated as an ASCII string. Negative 972 * strings are not allowed. 973 * 974 * This routine will ensure the values are within the range specified by 975 * table->extra1 (min) and table->extra2 (max). 976 * 977 * Returns 0 on success or an error on write when the range check fails. 978 */ 979 int proc_dou8vec_minmax(struct ctl_table *table, int write, 980 void *buffer, size_t *lenp, loff_t *ppos) 981 { 982 struct ctl_table tmp; 983 unsigned int min = 0, max = 255U, val; 984 u8 *data = table->data; 985 struct do_proc_douintvec_minmax_conv_param param = { 986 .min = &min, 987 .max = &max, 988 }; 989 int res; 990 991 /* Do not support arrays yet. */ 992 if (table->maxlen != sizeof(u8)) 993 return -EINVAL; 994 995 if (table->extra1) { 996 min = *(unsigned int *) table->extra1; 997 if (min > 255U) 998 return -EINVAL; 999 } 1000 if (table->extra2) { 1001 max = *(unsigned int *) table->extra2; 1002 if (max > 255U) 1003 return -EINVAL; 1004 } 1005 1006 tmp = *table; 1007 1008 tmp.maxlen = sizeof(val); 1009 tmp.data = &val; 1010 val = READ_ONCE(*data); 1011 res = do_proc_douintvec(&tmp, write, buffer, lenp, ppos, 1012 do_proc_douintvec_minmax_conv, ¶m); 1013 if (res) 1014 return res; 1015 if (write) 1016 WRITE_ONCE(*data, val); 1017 return 0; 1018 } 1019 EXPORT_SYMBOL_GPL(proc_dou8vec_minmax); 1020 1021 #ifdef CONFIG_MAGIC_SYSRQ 1022 static int sysrq_sysctl_handler(struct ctl_table *table, int write, 1023 void *buffer, size_t *lenp, loff_t *ppos) 1024 { 1025 int tmp, ret; 1026 1027 tmp = sysrq_mask(); 1028 1029 ret = __do_proc_dointvec(&tmp, table, write, buffer, 1030 lenp, ppos, NULL, NULL); 1031 if (ret || !write) 1032 return ret; 1033 1034 if (write) 1035 sysrq_toggle_support(tmp); 1036 1037 return 0; 1038 } 1039 #endif 1040 1041 static int __do_proc_doulongvec_minmax(void *data, struct ctl_table *table, 1042 int write, void *buffer, size_t *lenp, loff_t *ppos, 1043 unsigned long convmul, unsigned long convdiv) 1044 { 1045 unsigned long *i, *min, *max; 1046 int vleft, first = 1, err = 0; 1047 size_t left; 1048 char *p; 1049 1050 if (!data || !table->maxlen || !*lenp || (*ppos && !write)) { 1051 *lenp = 0; 1052 return 0; 1053 } 1054 1055 i = (unsigned long *) data; 1056 min = (unsigned long *) table->extra1; 1057 max = (unsigned long *) table->extra2; 1058 vleft = table->maxlen / sizeof(unsigned long); 1059 left = *lenp; 1060 1061 if (write) { 1062 if (proc_first_pos_non_zero_ignore(ppos, table)) 1063 goto out; 1064 1065 if (left > PAGE_SIZE - 1) 1066 left = PAGE_SIZE - 1; 1067 p = buffer; 1068 } 1069 1070 for (; left && vleft--; i++, first = 0) { 1071 unsigned long val; 1072 1073 if (write) { 1074 bool neg; 1075 1076 left -= proc_skip_spaces(&p); 1077 if (!left) 1078 break; 1079 1080 err = proc_get_long(&p, &left, &val, &neg, 1081 proc_wspace_sep, 1082 sizeof(proc_wspace_sep), NULL); 1083 if (err || neg) { 1084 err = -EINVAL; 1085 break; 1086 } 1087 1088 val = convmul * val / convdiv; 1089 if ((min && val < *min) || (max && val > *max)) { 1090 err = -EINVAL; 1091 break; 1092 } 1093 WRITE_ONCE(*i, val); 1094 } else { 1095 val = convdiv * READ_ONCE(*i) / convmul; 1096 if (!first) 1097 proc_put_char(&buffer, &left, '\t'); 1098 proc_put_long(&buffer, &left, val, false); 1099 } 1100 } 1101 1102 if (!write && !first && left && !err) 1103 proc_put_char(&buffer, &left, '\n'); 1104 if (write && !err) 1105 left -= proc_skip_spaces(&p); 1106 if (write && first) 1107 return err ? : -EINVAL; 1108 *lenp -= left; 1109 out: 1110 *ppos += *lenp; 1111 return err; 1112 } 1113 1114 static int do_proc_doulongvec_minmax(struct ctl_table *table, int write, 1115 void *buffer, size_t *lenp, loff_t *ppos, unsigned long convmul, 1116 unsigned long convdiv) 1117 { 1118 return __do_proc_doulongvec_minmax(table->data, table, write, 1119 buffer, lenp, ppos, convmul, convdiv); 1120 } 1121 1122 /** 1123 * proc_doulongvec_minmax - read a vector of long integers with min/max values 1124 * @table: the sysctl table 1125 * @write: %TRUE if this is a write to the sysctl file 1126 * @buffer: the user buffer 1127 * @lenp: the size of the user buffer 1128 * @ppos: file position 1129 * 1130 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 1131 * values from/to the user buffer, treated as an ASCII string. 1132 * 1133 * This routine will ensure the values are within the range specified by 1134 * table->extra1 (min) and table->extra2 (max). 1135 * 1136 * Returns 0 on success. 1137 */ 1138 int proc_doulongvec_minmax(struct ctl_table *table, int write, 1139 void *buffer, size_t *lenp, loff_t *ppos) 1140 { 1141 return do_proc_doulongvec_minmax(table, write, buffer, lenp, ppos, 1l, 1l); 1142 } 1143 1144 /** 1145 * proc_doulongvec_ms_jiffies_minmax - read a vector of millisecond values with min/max values 1146 * @table: the sysctl table 1147 * @write: %TRUE if this is a write to the sysctl file 1148 * @buffer: the user buffer 1149 * @lenp: the size of the user buffer 1150 * @ppos: file position 1151 * 1152 * Reads/writes up to table->maxlen/sizeof(unsigned long) unsigned long 1153 * values from/to the user buffer, treated as an ASCII string. The values 1154 * are treated as milliseconds, and converted to jiffies when they are stored. 1155 * 1156 * This routine will ensure the values are within the range specified by 1157 * table->extra1 (min) and table->extra2 (max). 1158 * 1159 * Returns 0 on success. 1160 */ 1161 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 1162 void *buffer, size_t *lenp, loff_t *ppos) 1163 { 1164 return do_proc_doulongvec_minmax(table, write, buffer, 1165 lenp, ppos, HZ, 1000l); 1166 } 1167 1168 1169 static int do_proc_dointvec_jiffies_conv(bool *negp, unsigned long *lvalp, 1170 int *valp, 1171 int write, void *data) 1172 { 1173 if (write) { 1174 if (*lvalp > INT_MAX / HZ) 1175 return 1; 1176 if (*negp) 1177 WRITE_ONCE(*valp, -*lvalp * HZ); 1178 else 1179 WRITE_ONCE(*valp, *lvalp * HZ); 1180 } else { 1181 int val = READ_ONCE(*valp); 1182 unsigned long lval; 1183 if (val < 0) { 1184 *negp = true; 1185 lval = -(unsigned long)val; 1186 } else { 1187 *negp = false; 1188 lval = (unsigned long)val; 1189 } 1190 *lvalp = lval / HZ; 1191 } 1192 return 0; 1193 } 1194 1195 static int do_proc_dointvec_userhz_jiffies_conv(bool *negp, unsigned long *lvalp, 1196 int *valp, 1197 int write, void *data) 1198 { 1199 if (write) { 1200 if (USER_HZ < HZ && *lvalp > (LONG_MAX / HZ) * USER_HZ) 1201 return 1; 1202 *valp = clock_t_to_jiffies(*negp ? -*lvalp : *lvalp); 1203 } else { 1204 int val = *valp; 1205 unsigned long lval; 1206 if (val < 0) { 1207 *negp = true; 1208 lval = -(unsigned long)val; 1209 } else { 1210 *negp = false; 1211 lval = (unsigned long)val; 1212 } 1213 *lvalp = jiffies_to_clock_t(lval); 1214 } 1215 return 0; 1216 } 1217 1218 static int do_proc_dointvec_ms_jiffies_conv(bool *negp, unsigned long *lvalp, 1219 int *valp, 1220 int write, void *data) 1221 { 1222 if (write) { 1223 unsigned long jif = msecs_to_jiffies(*negp ? -*lvalp : *lvalp); 1224 1225 if (jif > INT_MAX) 1226 return 1; 1227 WRITE_ONCE(*valp, (int)jif); 1228 } else { 1229 int val = READ_ONCE(*valp); 1230 unsigned long lval; 1231 if (val < 0) { 1232 *negp = true; 1233 lval = -(unsigned long)val; 1234 } else { 1235 *negp = false; 1236 lval = (unsigned long)val; 1237 } 1238 *lvalp = jiffies_to_msecs(lval); 1239 } 1240 return 0; 1241 } 1242 1243 /** 1244 * proc_dointvec_jiffies - read a vector of integers as seconds 1245 * @table: the sysctl table 1246 * @write: %TRUE if this is a write to the sysctl file 1247 * @buffer: the user buffer 1248 * @lenp: the size of the user buffer 1249 * @ppos: file position 1250 * 1251 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1252 * values from/to the user buffer, treated as an ASCII string. 1253 * The values read are assumed to be in seconds, and are converted into 1254 * jiffies. 1255 * 1256 * Returns 0 on success. 1257 */ 1258 int proc_dointvec_jiffies(struct ctl_table *table, int write, 1259 void *buffer, size_t *lenp, loff_t *ppos) 1260 { 1261 return do_proc_dointvec(table,write,buffer,lenp,ppos, 1262 do_proc_dointvec_jiffies_conv,NULL); 1263 } 1264 1265 /** 1266 * proc_dointvec_userhz_jiffies - read a vector of integers as 1/USER_HZ seconds 1267 * @table: the sysctl table 1268 * @write: %TRUE if this is a write to the sysctl file 1269 * @buffer: the user buffer 1270 * @lenp: the size of the user buffer 1271 * @ppos: pointer to the file position 1272 * 1273 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1274 * values from/to the user buffer, treated as an ASCII string. 1275 * The values read are assumed to be in 1/USER_HZ seconds, and 1276 * are converted into jiffies. 1277 * 1278 * Returns 0 on success. 1279 */ 1280 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 1281 void *buffer, size_t *lenp, loff_t *ppos) 1282 { 1283 return do_proc_dointvec(table,write,buffer,lenp,ppos, 1284 do_proc_dointvec_userhz_jiffies_conv,NULL); 1285 } 1286 1287 /** 1288 * proc_dointvec_ms_jiffies - read a vector of integers as 1 milliseconds 1289 * @table: the sysctl table 1290 * @write: %TRUE if this is a write to the sysctl file 1291 * @buffer: the user buffer 1292 * @lenp: the size of the user buffer 1293 * @ppos: file position 1294 * @ppos: the current position in the file 1295 * 1296 * Reads/writes up to table->maxlen/sizeof(unsigned int) integer 1297 * values from/to the user buffer, treated as an ASCII string. 1298 * The values read are assumed to be in 1/1000 seconds, and 1299 * are converted into jiffies. 1300 * 1301 * Returns 0 on success. 1302 */ 1303 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, void *buffer, 1304 size_t *lenp, loff_t *ppos) 1305 { 1306 return do_proc_dointvec(table, write, buffer, lenp, ppos, 1307 do_proc_dointvec_ms_jiffies_conv, NULL); 1308 } 1309 1310 static int proc_do_cad_pid(struct ctl_table *table, int write, void *buffer, 1311 size_t *lenp, loff_t *ppos) 1312 { 1313 struct pid *new_pid; 1314 pid_t tmp; 1315 int r; 1316 1317 tmp = pid_vnr(cad_pid); 1318 1319 r = __do_proc_dointvec(&tmp, table, write, buffer, 1320 lenp, ppos, NULL, NULL); 1321 if (r || !write) 1322 return r; 1323 1324 new_pid = find_get_pid(tmp); 1325 if (!new_pid) 1326 return -ESRCH; 1327 1328 put_pid(xchg(&cad_pid, new_pid)); 1329 return 0; 1330 } 1331 1332 /** 1333 * proc_do_large_bitmap - read/write from/to a large bitmap 1334 * @table: the sysctl table 1335 * @write: %TRUE if this is a write to the sysctl file 1336 * @buffer: the user buffer 1337 * @lenp: the size of the user buffer 1338 * @ppos: file position 1339 * 1340 * The bitmap is stored at table->data and the bitmap length (in bits) 1341 * in table->maxlen. 1342 * 1343 * We use a range comma separated format (e.g. 1,3-4,10-10) so that 1344 * large bitmaps may be represented in a compact manner. Writing into 1345 * the file will clear the bitmap then update it with the given input. 1346 * 1347 * Returns 0 on success. 1348 */ 1349 int proc_do_large_bitmap(struct ctl_table *table, int write, 1350 void *buffer, size_t *lenp, loff_t *ppos) 1351 { 1352 int err = 0; 1353 size_t left = *lenp; 1354 unsigned long bitmap_len = table->maxlen; 1355 unsigned long *bitmap = *(unsigned long **) table->data; 1356 unsigned long *tmp_bitmap = NULL; 1357 char tr_a[] = { '-', ',', '\n' }, tr_b[] = { ',', '\n', 0 }, c; 1358 1359 if (!bitmap || !bitmap_len || !left || (*ppos && !write)) { 1360 *lenp = 0; 1361 return 0; 1362 } 1363 1364 if (write) { 1365 char *p = buffer; 1366 size_t skipped = 0; 1367 1368 if (left > PAGE_SIZE - 1) { 1369 left = PAGE_SIZE - 1; 1370 /* How much of the buffer we'll skip this pass */ 1371 skipped = *lenp - left; 1372 } 1373 1374 tmp_bitmap = bitmap_zalloc(bitmap_len, GFP_KERNEL); 1375 if (!tmp_bitmap) 1376 return -ENOMEM; 1377 proc_skip_char(&p, &left, '\n'); 1378 while (!err && left) { 1379 unsigned long val_a, val_b; 1380 bool neg; 1381 size_t saved_left; 1382 1383 /* In case we stop parsing mid-number, we can reset */ 1384 saved_left = left; 1385 err = proc_get_long(&p, &left, &val_a, &neg, tr_a, 1386 sizeof(tr_a), &c); 1387 /* 1388 * If we consumed the entirety of a truncated buffer or 1389 * only one char is left (may be a "-"), then stop here, 1390 * reset, & come back for more. 1391 */ 1392 if ((left <= 1) && skipped) { 1393 left = saved_left; 1394 break; 1395 } 1396 1397 if (err) 1398 break; 1399 if (val_a >= bitmap_len || neg) { 1400 err = -EINVAL; 1401 break; 1402 } 1403 1404 val_b = val_a; 1405 if (left) { 1406 p++; 1407 left--; 1408 } 1409 1410 if (c == '-') { 1411 err = proc_get_long(&p, &left, &val_b, 1412 &neg, tr_b, sizeof(tr_b), 1413 &c); 1414 /* 1415 * If we consumed all of a truncated buffer or 1416 * then stop here, reset, & come back for more. 1417 */ 1418 if (!left && skipped) { 1419 left = saved_left; 1420 break; 1421 } 1422 1423 if (err) 1424 break; 1425 if (val_b >= bitmap_len || neg || 1426 val_a > val_b) { 1427 err = -EINVAL; 1428 break; 1429 } 1430 if (left) { 1431 p++; 1432 left--; 1433 } 1434 } 1435 1436 bitmap_set(tmp_bitmap, val_a, val_b - val_a + 1); 1437 proc_skip_char(&p, &left, '\n'); 1438 } 1439 left += skipped; 1440 } else { 1441 unsigned long bit_a, bit_b = 0; 1442 bool first = 1; 1443 1444 while (left) { 1445 bit_a = find_next_bit(bitmap, bitmap_len, bit_b); 1446 if (bit_a >= bitmap_len) 1447 break; 1448 bit_b = find_next_zero_bit(bitmap, bitmap_len, 1449 bit_a + 1) - 1; 1450 1451 if (!first) 1452 proc_put_char(&buffer, &left, ','); 1453 proc_put_long(&buffer, &left, bit_a, false); 1454 if (bit_a != bit_b) { 1455 proc_put_char(&buffer, &left, '-'); 1456 proc_put_long(&buffer, &left, bit_b, false); 1457 } 1458 1459 first = 0; bit_b++; 1460 } 1461 proc_put_char(&buffer, &left, '\n'); 1462 } 1463 1464 if (!err) { 1465 if (write) { 1466 if (*ppos) 1467 bitmap_or(bitmap, bitmap, tmp_bitmap, bitmap_len); 1468 else 1469 bitmap_copy(bitmap, tmp_bitmap, bitmap_len); 1470 } 1471 *lenp -= left; 1472 *ppos += *lenp; 1473 } 1474 1475 bitmap_free(tmp_bitmap); 1476 return err; 1477 } 1478 1479 #else /* CONFIG_PROC_SYSCTL */ 1480 1481 int proc_dostring(struct ctl_table *table, int write, 1482 void *buffer, size_t *lenp, loff_t *ppos) 1483 { 1484 return -ENOSYS; 1485 } 1486 1487 int proc_dobool(struct ctl_table *table, int write, 1488 void *buffer, size_t *lenp, loff_t *ppos) 1489 { 1490 return -ENOSYS; 1491 } 1492 1493 int proc_dointvec(struct ctl_table *table, int write, 1494 void *buffer, size_t *lenp, loff_t *ppos) 1495 { 1496 return -ENOSYS; 1497 } 1498 1499 int proc_douintvec(struct ctl_table *table, int write, 1500 void *buffer, size_t *lenp, loff_t *ppos) 1501 { 1502 return -ENOSYS; 1503 } 1504 1505 int proc_dointvec_minmax(struct ctl_table *table, int write, 1506 void *buffer, size_t *lenp, loff_t *ppos) 1507 { 1508 return -ENOSYS; 1509 } 1510 1511 int proc_douintvec_minmax(struct ctl_table *table, int write, 1512 void *buffer, size_t *lenp, loff_t *ppos) 1513 { 1514 return -ENOSYS; 1515 } 1516 1517 int proc_dou8vec_minmax(struct ctl_table *table, int write, 1518 void *buffer, size_t *lenp, loff_t *ppos) 1519 { 1520 return -ENOSYS; 1521 } 1522 1523 int proc_dointvec_jiffies(struct ctl_table *table, int write, 1524 void *buffer, size_t *lenp, loff_t *ppos) 1525 { 1526 return -ENOSYS; 1527 } 1528 1529 int proc_dointvec_userhz_jiffies(struct ctl_table *table, int write, 1530 void *buffer, size_t *lenp, loff_t *ppos) 1531 { 1532 return -ENOSYS; 1533 } 1534 1535 int proc_dointvec_ms_jiffies(struct ctl_table *table, int write, 1536 void *buffer, size_t *lenp, loff_t *ppos) 1537 { 1538 return -ENOSYS; 1539 } 1540 1541 int proc_doulongvec_minmax(struct ctl_table *table, int write, 1542 void *buffer, size_t *lenp, loff_t *ppos) 1543 { 1544 return -ENOSYS; 1545 } 1546 1547 int proc_doulongvec_ms_jiffies_minmax(struct ctl_table *table, int write, 1548 void *buffer, size_t *lenp, loff_t *ppos) 1549 { 1550 return -ENOSYS; 1551 } 1552 1553 int proc_do_large_bitmap(struct ctl_table *table, int write, 1554 void *buffer, size_t *lenp, loff_t *ppos) 1555 { 1556 return -ENOSYS; 1557 } 1558 1559 #endif /* CONFIG_PROC_SYSCTL */ 1560 1561 #if defined(CONFIG_SYSCTL) 1562 int proc_do_static_key(struct ctl_table *table, int write, 1563 void *buffer, size_t *lenp, loff_t *ppos) 1564 { 1565 struct static_key *key = (struct static_key *)table->data; 1566 static DEFINE_MUTEX(static_key_mutex); 1567 int val, ret; 1568 struct ctl_table tmp = { 1569 .data = &val, 1570 .maxlen = sizeof(val), 1571 .mode = table->mode, 1572 .extra1 = SYSCTL_ZERO, 1573 .extra2 = SYSCTL_ONE, 1574 }; 1575 1576 if (write && !capable(CAP_SYS_ADMIN)) 1577 return -EPERM; 1578 1579 mutex_lock(&static_key_mutex); 1580 val = static_key_enabled(key); 1581 ret = proc_dointvec_minmax(&tmp, write, buffer, lenp, ppos); 1582 if (write && !ret) { 1583 if (val) 1584 static_key_enable(key); 1585 else 1586 static_key_disable(key); 1587 } 1588 mutex_unlock(&static_key_mutex); 1589 return ret; 1590 } 1591 1592 static struct ctl_table kern_table[] = { 1593 #ifdef CONFIG_NUMA_BALANCING 1594 { 1595 .procname = "numa_balancing", 1596 .data = NULL, /* filled in by handler */ 1597 .maxlen = sizeof(unsigned int), 1598 .mode = 0644, 1599 .proc_handler = sysctl_numa_balancing, 1600 .extra1 = SYSCTL_ZERO, 1601 .extra2 = SYSCTL_FOUR, 1602 }, 1603 #endif /* CONFIG_NUMA_BALANCING */ 1604 { 1605 .procname = "panic", 1606 .data = &panic_timeout, 1607 .maxlen = sizeof(int), 1608 .mode = 0644, 1609 .proc_handler = proc_dointvec, 1610 }, 1611 #ifdef CONFIG_PROC_SYSCTL 1612 { 1613 .procname = "tainted", 1614 .maxlen = sizeof(long), 1615 .mode = 0644, 1616 .proc_handler = proc_taint, 1617 }, 1618 { 1619 .procname = "sysctl_writes_strict", 1620 .data = &sysctl_writes_strict, 1621 .maxlen = sizeof(int), 1622 .mode = 0644, 1623 .proc_handler = proc_dointvec_minmax, 1624 .extra1 = SYSCTL_NEG_ONE, 1625 .extra2 = SYSCTL_ONE, 1626 }, 1627 #endif 1628 { 1629 .procname = "print-fatal-signals", 1630 .data = &print_fatal_signals, 1631 .maxlen = sizeof(int), 1632 .mode = 0644, 1633 .proc_handler = proc_dointvec, 1634 }, 1635 #ifdef CONFIG_SPARC 1636 { 1637 .procname = "reboot-cmd", 1638 .data = reboot_command, 1639 .maxlen = 256, 1640 .mode = 0644, 1641 .proc_handler = proc_dostring, 1642 }, 1643 { 1644 .procname = "stop-a", 1645 .data = &stop_a_enabled, 1646 .maxlen = sizeof (int), 1647 .mode = 0644, 1648 .proc_handler = proc_dointvec, 1649 }, 1650 { 1651 .procname = "scons-poweroff", 1652 .data = &scons_pwroff, 1653 .maxlen = sizeof (int), 1654 .mode = 0644, 1655 .proc_handler = proc_dointvec, 1656 }, 1657 #endif 1658 #ifdef CONFIG_SPARC64 1659 { 1660 .procname = "tsb-ratio", 1661 .data = &sysctl_tsb_ratio, 1662 .maxlen = sizeof (int), 1663 .mode = 0644, 1664 .proc_handler = proc_dointvec, 1665 }, 1666 #endif 1667 #ifdef CONFIG_PARISC 1668 { 1669 .procname = "soft-power", 1670 .data = &pwrsw_enabled, 1671 .maxlen = sizeof (int), 1672 .mode = 0644, 1673 .proc_handler = proc_dointvec, 1674 }, 1675 #endif 1676 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_ALLOW 1677 { 1678 .procname = "unaligned-trap", 1679 .data = &unaligned_enabled, 1680 .maxlen = sizeof (int), 1681 .mode = 0644, 1682 .proc_handler = proc_dointvec, 1683 }, 1684 #endif 1685 #ifdef CONFIG_STACK_TRACER 1686 { 1687 .procname = "stack_tracer_enabled", 1688 .data = &stack_tracer_enabled, 1689 .maxlen = sizeof(int), 1690 .mode = 0644, 1691 .proc_handler = stack_trace_sysctl, 1692 }, 1693 #endif 1694 #ifdef CONFIG_TRACING 1695 { 1696 .procname = "ftrace_dump_on_oops", 1697 .data = &ftrace_dump_on_oops, 1698 .maxlen = sizeof(int), 1699 .mode = 0644, 1700 .proc_handler = proc_dointvec, 1701 }, 1702 { 1703 .procname = "traceoff_on_warning", 1704 .data = &__disable_trace_on_warning, 1705 .maxlen = sizeof(__disable_trace_on_warning), 1706 .mode = 0644, 1707 .proc_handler = proc_dointvec, 1708 }, 1709 { 1710 .procname = "tracepoint_printk", 1711 .data = &tracepoint_printk, 1712 .maxlen = sizeof(tracepoint_printk), 1713 .mode = 0644, 1714 .proc_handler = tracepoint_printk_sysctl, 1715 }, 1716 #endif 1717 #ifdef CONFIG_MODULES 1718 { 1719 .procname = "modprobe", 1720 .data = &modprobe_path, 1721 .maxlen = KMOD_PATH_LEN, 1722 .mode = 0644, 1723 .proc_handler = proc_dostring, 1724 }, 1725 { 1726 .procname = "modules_disabled", 1727 .data = &modules_disabled, 1728 .maxlen = sizeof(int), 1729 .mode = 0644, 1730 /* only handle a transition from default "0" to "1" */ 1731 .proc_handler = proc_dointvec_minmax, 1732 .extra1 = SYSCTL_ONE, 1733 .extra2 = SYSCTL_ONE, 1734 }, 1735 #endif 1736 #ifdef CONFIG_UEVENT_HELPER 1737 { 1738 .procname = "hotplug", 1739 .data = &uevent_helper, 1740 .maxlen = UEVENT_HELPER_PATH_LEN, 1741 .mode = 0644, 1742 .proc_handler = proc_dostring, 1743 }, 1744 #endif 1745 #ifdef CONFIG_MAGIC_SYSRQ 1746 { 1747 .procname = "sysrq", 1748 .data = NULL, 1749 .maxlen = sizeof (int), 1750 .mode = 0644, 1751 .proc_handler = sysrq_sysctl_handler, 1752 }, 1753 #endif 1754 #ifdef CONFIG_PROC_SYSCTL 1755 { 1756 .procname = "cad_pid", 1757 .data = NULL, 1758 .maxlen = sizeof (int), 1759 .mode = 0600, 1760 .proc_handler = proc_do_cad_pid, 1761 }, 1762 #endif 1763 { 1764 .procname = "threads-max", 1765 .data = NULL, 1766 .maxlen = sizeof(int), 1767 .mode = 0644, 1768 .proc_handler = sysctl_max_threads, 1769 }, 1770 { 1771 .procname = "usermodehelper", 1772 .mode = 0555, 1773 .child = usermodehelper_table, 1774 }, 1775 { 1776 .procname = "overflowuid", 1777 .data = &overflowuid, 1778 .maxlen = sizeof(int), 1779 .mode = 0644, 1780 .proc_handler = proc_dointvec_minmax, 1781 .extra1 = SYSCTL_ZERO, 1782 .extra2 = SYSCTL_MAXOLDUID, 1783 }, 1784 { 1785 .procname = "overflowgid", 1786 .data = &overflowgid, 1787 .maxlen = sizeof(int), 1788 .mode = 0644, 1789 .proc_handler = proc_dointvec_minmax, 1790 .extra1 = SYSCTL_ZERO, 1791 .extra2 = SYSCTL_MAXOLDUID, 1792 }, 1793 #ifdef CONFIG_S390 1794 { 1795 .procname = "userprocess_debug", 1796 .data = &show_unhandled_signals, 1797 .maxlen = sizeof(int), 1798 .mode = 0644, 1799 .proc_handler = proc_dointvec, 1800 }, 1801 #endif 1802 { 1803 .procname = "pid_max", 1804 .data = &pid_max, 1805 .maxlen = sizeof (int), 1806 .mode = 0644, 1807 .proc_handler = proc_dointvec_minmax, 1808 .extra1 = &pid_max_min, 1809 .extra2 = &pid_max_max, 1810 }, 1811 { 1812 .procname = "panic_on_oops", 1813 .data = &panic_on_oops, 1814 .maxlen = sizeof(int), 1815 .mode = 0644, 1816 .proc_handler = proc_dointvec, 1817 }, 1818 { 1819 .procname = "panic_print", 1820 .data = &panic_print, 1821 .maxlen = sizeof(unsigned long), 1822 .mode = 0644, 1823 .proc_handler = proc_doulongvec_minmax, 1824 }, 1825 { 1826 .procname = "ngroups_max", 1827 .data = (void *)&ngroups_max, 1828 .maxlen = sizeof (int), 1829 .mode = 0444, 1830 .proc_handler = proc_dointvec, 1831 }, 1832 { 1833 .procname = "cap_last_cap", 1834 .data = (void *)&cap_last_cap, 1835 .maxlen = sizeof(int), 1836 .mode = 0444, 1837 .proc_handler = proc_dointvec, 1838 }, 1839 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86) 1840 { 1841 .procname = "unknown_nmi_panic", 1842 .data = &unknown_nmi_panic, 1843 .maxlen = sizeof (int), 1844 .mode = 0644, 1845 .proc_handler = proc_dointvec, 1846 }, 1847 #endif 1848 1849 #if (defined(CONFIG_X86_32) || defined(CONFIG_PARISC)) && \ 1850 defined(CONFIG_DEBUG_STACKOVERFLOW) 1851 { 1852 .procname = "panic_on_stackoverflow", 1853 .data = &sysctl_panic_on_stackoverflow, 1854 .maxlen = sizeof(int), 1855 .mode = 0644, 1856 .proc_handler = proc_dointvec, 1857 }, 1858 #endif 1859 #if defined(CONFIG_X86) 1860 { 1861 .procname = "panic_on_unrecovered_nmi", 1862 .data = &panic_on_unrecovered_nmi, 1863 .maxlen = sizeof(int), 1864 .mode = 0644, 1865 .proc_handler = proc_dointvec, 1866 }, 1867 { 1868 .procname = "panic_on_io_nmi", 1869 .data = &panic_on_io_nmi, 1870 .maxlen = sizeof(int), 1871 .mode = 0644, 1872 .proc_handler = proc_dointvec, 1873 }, 1874 { 1875 .procname = "bootloader_type", 1876 .data = &bootloader_type, 1877 .maxlen = sizeof (int), 1878 .mode = 0444, 1879 .proc_handler = proc_dointvec, 1880 }, 1881 { 1882 .procname = "bootloader_version", 1883 .data = &bootloader_version, 1884 .maxlen = sizeof (int), 1885 .mode = 0444, 1886 .proc_handler = proc_dointvec, 1887 }, 1888 { 1889 .procname = "io_delay_type", 1890 .data = &io_delay_type, 1891 .maxlen = sizeof(int), 1892 .mode = 0644, 1893 .proc_handler = proc_dointvec, 1894 }, 1895 #endif 1896 #if defined(CONFIG_MMU) 1897 { 1898 .procname = "randomize_va_space", 1899 .data = &randomize_va_space, 1900 .maxlen = sizeof(int), 1901 .mode = 0644, 1902 .proc_handler = proc_dointvec, 1903 }, 1904 #endif 1905 #if defined(CONFIG_S390) && defined(CONFIG_SMP) 1906 { 1907 .procname = "spin_retry", 1908 .data = &spin_retry, 1909 .maxlen = sizeof (int), 1910 .mode = 0644, 1911 .proc_handler = proc_dointvec, 1912 }, 1913 #endif 1914 #if defined(CONFIG_ACPI_SLEEP) && defined(CONFIG_X86) 1915 { 1916 .procname = "acpi_video_flags", 1917 .data = &acpi_realmode_flags, 1918 .maxlen = sizeof (unsigned long), 1919 .mode = 0644, 1920 .proc_handler = proc_doulongvec_minmax, 1921 }, 1922 #endif 1923 #ifdef CONFIG_SYSCTL_ARCH_UNALIGN_NO_WARN 1924 { 1925 .procname = "ignore-unaligned-usertrap", 1926 .data = &no_unaligned_warning, 1927 .maxlen = sizeof (int), 1928 .mode = 0644, 1929 .proc_handler = proc_dointvec, 1930 }, 1931 #endif 1932 #ifdef CONFIG_IA64 1933 { 1934 .procname = "unaligned-dump-stack", 1935 .data = &unaligned_dump_stack, 1936 .maxlen = sizeof (int), 1937 .mode = 0644, 1938 .proc_handler = proc_dointvec, 1939 }, 1940 #endif 1941 #ifdef CONFIG_RT_MUTEXES 1942 { 1943 .procname = "max_lock_depth", 1944 .data = &max_lock_depth, 1945 .maxlen = sizeof(int), 1946 .mode = 0644, 1947 .proc_handler = proc_dointvec, 1948 }, 1949 #endif 1950 #ifdef CONFIG_KEYS 1951 { 1952 .procname = "keys", 1953 .mode = 0555, 1954 .child = key_sysctls, 1955 }, 1956 #endif 1957 #ifdef CONFIG_PERF_EVENTS 1958 /* 1959 * User-space scripts rely on the existence of this file 1960 * as a feature check for perf_events being enabled. 1961 * 1962 * So it's an ABI, do not remove! 1963 */ 1964 { 1965 .procname = "perf_event_paranoid", 1966 .data = &sysctl_perf_event_paranoid, 1967 .maxlen = sizeof(sysctl_perf_event_paranoid), 1968 .mode = 0644, 1969 .proc_handler = proc_dointvec, 1970 }, 1971 { 1972 .procname = "perf_event_mlock_kb", 1973 .data = &sysctl_perf_event_mlock, 1974 .maxlen = sizeof(sysctl_perf_event_mlock), 1975 .mode = 0644, 1976 .proc_handler = proc_dointvec, 1977 }, 1978 { 1979 .procname = "perf_event_max_sample_rate", 1980 .data = &sysctl_perf_event_sample_rate, 1981 .maxlen = sizeof(sysctl_perf_event_sample_rate), 1982 .mode = 0644, 1983 .proc_handler = perf_proc_update_handler, 1984 .extra1 = SYSCTL_ONE, 1985 }, 1986 { 1987 .procname = "perf_cpu_time_max_percent", 1988 .data = &sysctl_perf_cpu_time_max_percent, 1989 .maxlen = sizeof(sysctl_perf_cpu_time_max_percent), 1990 .mode = 0644, 1991 .proc_handler = perf_cpu_time_max_percent_handler, 1992 .extra1 = SYSCTL_ZERO, 1993 .extra2 = SYSCTL_ONE_HUNDRED, 1994 }, 1995 { 1996 .procname = "perf_event_max_stack", 1997 .data = &sysctl_perf_event_max_stack, 1998 .maxlen = sizeof(sysctl_perf_event_max_stack), 1999 .mode = 0644, 2000 .proc_handler = perf_event_max_stack_handler, 2001 .extra1 = SYSCTL_ZERO, 2002 .extra2 = (void *)&six_hundred_forty_kb, 2003 }, 2004 { 2005 .procname = "perf_event_max_contexts_per_stack", 2006 .data = &sysctl_perf_event_max_contexts_per_stack, 2007 .maxlen = sizeof(sysctl_perf_event_max_contexts_per_stack), 2008 .mode = 0644, 2009 .proc_handler = perf_event_max_stack_handler, 2010 .extra1 = SYSCTL_ZERO, 2011 .extra2 = SYSCTL_ONE_THOUSAND, 2012 }, 2013 #endif 2014 { 2015 .procname = "panic_on_warn", 2016 .data = &panic_on_warn, 2017 .maxlen = sizeof(int), 2018 .mode = 0644, 2019 .proc_handler = proc_dointvec_minmax, 2020 .extra1 = SYSCTL_ZERO, 2021 .extra2 = SYSCTL_ONE, 2022 }, 2023 #if defined(CONFIG_TREE_RCU) 2024 { 2025 .procname = "panic_on_rcu_stall", 2026 .data = &sysctl_panic_on_rcu_stall, 2027 .maxlen = sizeof(sysctl_panic_on_rcu_stall), 2028 .mode = 0644, 2029 .proc_handler = proc_dointvec_minmax, 2030 .extra1 = SYSCTL_ZERO, 2031 .extra2 = SYSCTL_ONE, 2032 }, 2033 #endif 2034 #if defined(CONFIG_TREE_RCU) 2035 { 2036 .procname = "max_rcu_stall_to_panic", 2037 .data = &sysctl_max_rcu_stall_to_panic, 2038 .maxlen = sizeof(sysctl_max_rcu_stall_to_panic), 2039 .mode = 0644, 2040 .proc_handler = proc_dointvec_minmax, 2041 .extra1 = SYSCTL_ONE, 2042 .extra2 = SYSCTL_INT_MAX, 2043 }, 2044 #endif 2045 { } 2046 }; 2047 2048 static struct ctl_table vm_table[] = { 2049 { 2050 .procname = "overcommit_memory", 2051 .data = &sysctl_overcommit_memory, 2052 .maxlen = sizeof(sysctl_overcommit_memory), 2053 .mode = 0644, 2054 .proc_handler = overcommit_policy_handler, 2055 .extra1 = SYSCTL_ZERO, 2056 .extra2 = SYSCTL_TWO, 2057 }, 2058 { 2059 .procname = "overcommit_ratio", 2060 .data = &sysctl_overcommit_ratio, 2061 .maxlen = sizeof(sysctl_overcommit_ratio), 2062 .mode = 0644, 2063 .proc_handler = overcommit_ratio_handler, 2064 }, 2065 { 2066 .procname = "overcommit_kbytes", 2067 .data = &sysctl_overcommit_kbytes, 2068 .maxlen = sizeof(sysctl_overcommit_kbytes), 2069 .mode = 0644, 2070 .proc_handler = overcommit_kbytes_handler, 2071 }, 2072 { 2073 .procname = "page-cluster", 2074 .data = &page_cluster, 2075 .maxlen = sizeof(int), 2076 .mode = 0644, 2077 .proc_handler = proc_dointvec_minmax, 2078 .extra1 = SYSCTL_ZERO, 2079 }, 2080 { 2081 .procname = "dirtytime_expire_seconds", 2082 .data = &dirtytime_expire_interval, 2083 .maxlen = sizeof(dirtytime_expire_interval), 2084 .mode = 0644, 2085 .proc_handler = dirtytime_interval_handler, 2086 .extra1 = SYSCTL_ZERO, 2087 }, 2088 { 2089 .procname = "swappiness", 2090 .data = &vm_swappiness, 2091 .maxlen = sizeof(vm_swappiness), 2092 .mode = 0644, 2093 .proc_handler = proc_dointvec_minmax, 2094 .extra1 = SYSCTL_ZERO, 2095 .extra2 = SYSCTL_TWO_HUNDRED, 2096 }, 2097 #ifdef CONFIG_NUMA 2098 { 2099 .procname = "numa_stat", 2100 .data = &sysctl_vm_numa_stat, 2101 .maxlen = sizeof(int), 2102 .mode = 0644, 2103 .proc_handler = sysctl_vm_numa_stat_handler, 2104 .extra1 = SYSCTL_ZERO, 2105 .extra2 = SYSCTL_ONE, 2106 }, 2107 #endif 2108 #ifdef CONFIG_HUGETLB_PAGE 2109 { 2110 .procname = "nr_hugepages", 2111 .data = NULL, 2112 .maxlen = sizeof(unsigned long), 2113 .mode = 0644, 2114 .proc_handler = hugetlb_sysctl_handler, 2115 }, 2116 #ifdef CONFIG_NUMA 2117 { 2118 .procname = "nr_hugepages_mempolicy", 2119 .data = NULL, 2120 .maxlen = sizeof(unsigned long), 2121 .mode = 0644, 2122 .proc_handler = &hugetlb_mempolicy_sysctl_handler, 2123 }, 2124 #endif 2125 { 2126 .procname = "hugetlb_shm_group", 2127 .data = &sysctl_hugetlb_shm_group, 2128 .maxlen = sizeof(gid_t), 2129 .mode = 0644, 2130 .proc_handler = proc_dointvec, 2131 }, 2132 { 2133 .procname = "nr_overcommit_hugepages", 2134 .data = NULL, 2135 .maxlen = sizeof(unsigned long), 2136 .mode = 0644, 2137 .proc_handler = hugetlb_overcommit_handler, 2138 }, 2139 #endif 2140 { 2141 .procname = "lowmem_reserve_ratio", 2142 .data = &sysctl_lowmem_reserve_ratio, 2143 .maxlen = sizeof(sysctl_lowmem_reserve_ratio), 2144 .mode = 0644, 2145 .proc_handler = lowmem_reserve_ratio_sysctl_handler, 2146 }, 2147 { 2148 .procname = "drop_caches", 2149 .data = &sysctl_drop_caches, 2150 .maxlen = sizeof(int), 2151 .mode = 0200, 2152 .proc_handler = drop_caches_sysctl_handler, 2153 .extra1 = SYSCTL_ONE, 2154 .extra2 = SYSCTL_FOUR, 2155 }, 2156 #ifdef CONFIG_COMPACTION 2157 { 2158 .procname = "compact_memory", 2159 .data = NULL, 2160 .maxlen = sizeof(int), 2161 .mode = 0200, 2162 .proc_handler = sysctl_compaction_handler, 2163 }, 2164 { 2165 .procname = "compaction_proactiveness", 2166 .data = &sysctl_compaction_proactiveness, 2167 .maxlen = sizeof(sysctl_compaction_proactiveness), 2168 .mode = 0644, 2169 .proc_handler = compaction_proactiveness_sysctl_handler, 2170 .extra1 = SYSCTL_ZERO, 2171 .extra2 = SYSCTL_ONE_HUNDRED, 2172 }, 2173 { 2174 .procname = "extfrag_threshold", 2175 .data = &sysctl_extfrag_threshold, 2176 .maxlen = sizeof(int), 2177 .mode = 0644, 2178 .proc_handler = proc_dointvec_minmax, 2179 .extra1 = SYSCTL_ZERO, 2180 .extra2 = (void *)&max_extfrag_threshold, 2181 }, 2182 { 2183 .procname = "compact_unevictable_allowed", 2184 .data = &sysctl_compact_unevictable_allowed, 2185 .maxlen = sizeof(int), 2186 .mode = 0644, 2187 .proc_handler = proc_dointvec_minmax_warn_RT_change, 2188 .extra1 = SYSCTL_ZERO, 2189 .extra2 = SYSCTL_ONE, 2190 }, 2191 2192 #endif /* CONFIG_COMPACTION */ 2193 { 2194 .procname = "min_free_kbytes", 2195 .data = &min_free_kbytes, 2196 .maxlen = sizeof(min_free_kbytes), 2197 .mode = 0644, 2198 .proc_handler = min_free_kbytes_sysctl_handler, 2199 .extra1 = SYSCTL_ZERO, 2200 }, 2201 { 2202 .procname = "watermark_boost_factor", 2203 .data = &watermark_boost_factor, 2204 .maxlen = sizeof(watermark_boost_factor), 2205 .mode = 0644, 2206 .proc_handler = proc_dointvec_minmax, 2207 .extra1 = SYSCTL_ZERO, 2208 }, 2209 { 2210 .procname = "watermark_scale_factor", 2211 .data = &watermark_scale_factor, 2212 .maxlen = sizeof(watermark_scale_factor), 2213 .mode = 0644, 2214 .proc_handler = watermark_scale_factor_sysctl_handler, 2215 .extra1 = SYSCTL_ONE, 2216 .extra2 = SYSCTL_THREE_THOUSAND, 2217 }, 2218 { 2219 .procname = "percpu_pagelist_high_fraction", 2220 .data = &percpu_pagelist_high_fraction, 2221 .maxlen = sizeof(percpu_pagelist_high_fraction), 2222 .mode = 0644, 2223 .proc_handler = percpu_pagelist_high_fraction_sysctl_handler, 2224 .extra1 = SYSCTL_ZERO, 2225 }, 2226 { 2227 .procname = "page_lock_unfairness", 2228 .data = &sysctl_page_lock_unfairness, 2229 .maxlen = sizeof(sysctl_page_lock_unfairness), 2230 .mode = 0644, 2231 .proc_handler = proc_dointvec_minmax, 2232 .extra1 = SYSCTL_ZERO, 2233 }, 2234 #ifdef CONFIG_MMU 2235 { 2236 .procname = "max_map_count", 2237 .data = &sysctl_max_map_count, 2238 .maxlen = sizeof(sysctl_max_map_count), 2239 .mode = 0644, 2240 .proc_handler = proc_dointvec_minmax, 2241 .extra1 = SYSCTL_ZERO, 2242 }, 2243 #else 2244 { 2245 .procname = "nr_trim_pages", 2246 .data = &sysctl_nr_trim_pages, 2247 .maxlen = sizeof(sysctl_nr_trim_pages), 2248 .mode = 0644, 2249 .proc_handler = proc_dointvec_minmax, 2250 .extra1 = SYSCTL_ZERO, 2251 }, 2252 #endif 2253 { 2254 .procname = "vfs_cache_pressure", 2255 .data = &sysctl_vfs_cache_pressure, 2256 .maxlen = sizeof(sysctl_vfs_cache_pressure), 2257 .mode = 0644, 2258 .proc_handler = proc_dointvec_minmax, 2259 .extra1 = SYSCTL_ZERO, 2260 }, 2261 #if defined(HAVE_ARCH_PICK_MMAP_LAYOUT) || \ 2262 defined(CONFIG_ARCH_WANT_DEFAULT_TOPDOWN_MMAP_LAYOUT) 2263 { 2264 .procname = "legacy_va_layout", 2265 .data = &sysctl_legacy_va_layout, 2266 .maxlen = sizeof(sysctl_legacy_va_layout), 2267 .mode = 0644, 2268 .proc_handler = proc_dointvec_minmax, 2269 .extra1 = SYSCTL_ZERO, 2270 }, 2271 #endif 2272 #ifdef CONFIG_NUMA 2273 { 2274 .procname = "zone_reclaim_mode", 2275 .data = &node_reclaim_mode, 2276 .maxlen = sizeof(node_reclaim_mode), 2277 .mode = 0644, 2278 .proc_handler = proc_dointvec_minmax, 2279 .extra1 = SYSCTL_ZERO, 2280 }, 2281 { 2282 .procname = "min_unmapped_ratio", 2283 .data = &sysctl_min_unmapped_ratio, 2284 .maxlen = sizeof(sysctl_min_unmapped_ratio), 2285 .mode = 0644, 2286 .proc_handler = sysctl_min_unmapped_ratio_sysctl_handler, 2287 .extra1 = SYSCTL_ZERO, 2288 .extra2 = SYSCTL_ONE_HUNDRED, 2289 }, 2290 { 2291 .procname = "min_slab_ratio", 2292 .data = &sysctl_min_slab_ratio, 2293 .maxlen = sizeof(sysctl_min_slab_ratio), 2294 .mode = 0644, 2295 .proc_handler = sysctl_min_slab_ratio_sysctl_handler, 2296 .extra1 = SYSCTL_ZERO, 2297 .extra2 = SYSCTL_ONE_HUNDRED, 2298 }, 2299 #endif 2300 #ifdef CONFIG_SMP 2301 { 2302 .procname = "stat_interval", 2303 .data = &sysctl_stat_interval, 2304 .maxlen = sizeof(sysctl_stat_interval), 2305 .mode = 0644, 2306 .proc_handler = proc_dointvec_jiffies, 2307 }, 2308 { 2309 .procname = "stat_refresh", 2310 .data = NULL, 2311 .maxlen = 0, 2312 .mode = 0600, 2313 .proc_handler = vmstat_refresh, 2314 }, 2315 #endif 2316 #ifdef CONFIG_MMU 2317 { 2318 .procname = "mmap_min_addr", 2319 .data = &dac_mmap_min_addr, 2320 .maxlen = sizeof(unsigned long), 2321 .mode = 0644, 2322 .proc_handler = mmap_min_addr_handler, 2323 }, 2324 #endif 2325 #ifdef CONFIG_NUMA 2326 { 2327 .procname = "numa_zonelist_order", 2328 .data = &numa_zonelist_order, 2329 .maxlen = NUMA_ZONELIST_ORDER_LEN, 2330 .mode = 0644, 2331 .proc_handler = numa_zonelist_order_handler, 2332 }, 2333 #endif 2334 #if (defined(CONFIG_X86_32) && !defined(CONFIG_UML))|| \ 2335 (defined(CONFIG_SUPERH) && defined(CONFIG_VSYSCALL)) 2336 { 2337 .procname = "vdso_enabled", 2338 #ifdef CONFIG_X86_32 2339 .data = &vdso32_enabled, 2340 .maxlen = sizeof(vdso32_enabled), 2341 #else 2342 .data = &vdso_enabled, 2343 .maxlen = sizeof(vdso_enabled), 2344 #endif 2345 .mode = 0644, 2346 .proc_handler = proc_dointvec, 2347 .extra1 = SYSCTL_ZERO, 2348 }, 2349 #endif 2350 #ifdef CONFIG_MEMORY_FAILURE 2351 { 2352 .procname = "memory_failure_early_kill", 2353 .data = &sysctl_memory_failure_early_kill, 2354 .maxlen = sizeof(sysctl_memory_failure_early_kill), 2355 .mode = 0644, 2356 .proc_handler = proc_dointvec_minmax, 2357 .extra1 = SYSCTL_ZERO, 2358 .extra2 = SYSCTL_ONE, 2359 }, 2360 { 2361 .procname = "memory_failure_recovery", 2362 .data = &sysctl_memory_failure_recovery, 2363 .maxlen = sizeof(sysctl_memory_failure_recovery), 2364 .mode = 0644, 2365 .proc_handler = proc_dointvec_minmax, 2366 .extra1 = SYSCTL_ZERO, 2367 .extra2 = SYSCTL_ONE, 2368 }, 2369 #endif 2370 { 2371 .procname = "user_reserve_kbytes", 2372 .data = &sysctl_user_reserve_kbytes, 2373 .maxlen = sizeof(sysctl_user_reserve_kbytes), 2374 .mode = 0644, 2375 .proc_handler = proc_doulongvec_minmax, 2376 }, 2377 { 2378 .procname = "admin_reserve_kbytes", 2379 .data = &sysctl_admin_reserve_kbytes, 2380 .maxlen = sizeof(sysctl_admin_reserve_kbytes), 2381 .mode = 0644, 2382 .proc_handler = proc_doulongvec_minmax, 2383 }, 2384 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_BITS 2385 { 2386 .procname = "mmap_rnd_bits", 2387 .data = &mmap_rnd_bits, 2388 .maxlen = sizeof(mmap_rnd_bits), 2389 .mode = 0600, 2390 .proc_handler = proc_dointvec_minmax, 2391 .extra1 = (void *)&mmap_rnd_bits_min, 2392 .extra2 = (void *)&mmap_rnd_bits_max, 2393 }, 2394 #endif 2395 #ifdef CONFIG_HAVE_ARCH_MMAP_RND_COMPAT_BITS 2396 { 2397 .procname = "mmap_rnd_compat_bits", 2398 .data = &mmap_rnd_compat_bits, 2399 .maxlen = sizeof(mmap_rnd_compat_bits), 2400 .mode = 0600, 2401 .proc_handler = proc_dointvec_minmax, 2402 .extra1 = (void *)&mmap_rnd_compat_bits_min, 2403 .extra2 = (void *)&mmap_rnd_compat_bits_max, 2404 }, 2405 #endif 2406 #ifdef CONFIG_USERFAULTFD 2407 { 2408 .procname = "unprivileged_userfaultfd", 2409 .data = &sysctl_unprivileged_userfaultfd, 2410 .maxlen = sizeof(sysctl_unprivileged_userfaultfd), 2411 .mode = 0644, 2412 .proc_handler = proc_dointvec_minmax, 2413 .extra1 = SYSCTL_ZERO, 2414 .extra2 = SYSCTL_ONE, 2415 }, 2416 #endif 2417 { } 2418 }; 2419 2420 static struct ctl_table debug_table[] = { 2421 #ifdef CONFIG_SYSCTL_EXCEPTION_TRACE 2422 { 2423 .procname = "exception-trace", 2424 .data = &show_unhandled_signals, 2425 .maxlen = sizeof(int), 2426 .mode = 0644, 2427 .proc_handler = proc_dointvec 2428 }, 2429 #endif 2430 { } 2431 }; 2432 2433 static struct ctl_table dev_table[] = { 2434 { } 2435 }; 2436 2437 DECLARE_SYSCTL_BASE(kernel, kern_table); 2438 DECLARE_SYSCTL_BASE(vm, vm_table); 2439 DECLARE_SYSCTL_BASE(debug, debug_table); 2440 DECLARE_SYSCTL_BASE(dev, dev_table); 2441 2442 int __init sysctl_init_bases(void) 2443 { 2444 register_sysctl_base(kernel); 2445 register_sysctl_base(vm); 2446 register_sysctl_base(debug); 2447 register_sysctl_base(dev); 2448 2449 return 0; 2450 } 2451 #endif /* CONFIG_SYSCTL */ 2452 /* 2453 * No sense putting this after each symbol definition, twice, 2454 * exception granted :-) 2455 */ 2456 EXPORT_SYMBOL(proc_dobool); 2457 EXPORT_SYMBOL(proc_dointvec); 2458 EXPORT_SYMBOL(proc_douintvec); 2459 EXPORT_SYMBOL(proc_dointvec_jiffies); 2460 EXPORT_SYMBOL(proc_dointvec_minmax); 2461 EXPORT_SYMBOL_GPL(proc_douintvec_minmax); 2462 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies); 2463 EXPORT_SYMBOL(proc_dointvec_ms_jiffies); 2464 EXPORT_SYMBOL(proc_dostring); 2465 EXPORT_SYMBOL(proc_doulongvec_minmax); 2466 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax); 2467 EXPORT_SYMBOL(proc_do_large_bitmap); 2468