diff options
| -rw-r--r-- | mm/mremap.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/mm/mremap.c b/mm/mremap.c index 3320616ed93f..e3edef6b7a12 100644 --- a/mm/mremap.c +++ b/mm/mremap.c | |||
| @@ -516,6 +516,23 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len, | |||
| 516 | if (addr + old_len > new_addr && new_addr + new_len > addr) | 516 | if (addr + old_len > new_addr && new_addr + new_len > addr) |
| 517 | goto out; | 517 | goto out; |
| 518 | 518 | ||
| 519 | /* | ||
| 520 | * move_vma() need us to stay 4 maps below the threshold, otherwise | ||
| 521 | * it will bail out at the very beginning. | ||
| 522 | * That is a problem if we have already unmaped the regions here | ||
| 523 | * (new_addr, and old_addr), because userspace will not know the | ||
| 524 | * state of the vma's after it gets -ENOMEM. | ||
| 525 | * So, to avoid such scenario we can pre-compute if the whole | ||
| 526 | * operation has high chances to success map-wise. | ||
| 527 | * Worst-scenario case is when both vma's (new_addr and old_addr) get | ||
| 528 | * split in 3 before unmaping it. | ||
| 529 | * That means 2 more maps (1 for each) to the ones we already hold. | ||
| 530 | * Check whether current map count plus 2 still leads us to 4 maps below | ||
| 531 | * the threshold, otherwise return -ENOMEM here to be more safe. | ||
| 532 | */ | ||
| 533 | if ((mm->map_count + 2) >= sysctl_max_map_count - 3) | ||
| 534 | return -ENOMEM; | ||
| 535 | |||
| 519 | ret = do_munmap(mm, new_addr, new_len, uf_unmap_early); | 536 | ret = do_munmap(mm, new_addr, new_len, uf_unmap_early); |
| 520 | if (ret) | 537 | if (ret) |
| 521 | goto out; | 538 | goto out; |
