Re: [PATCH] mm: nommu: free unused resources when mremap shrinks the vma

From: Andrew Morton

Date: Fri Jul 10 2026 - 20:43:49 EST


On Fri, 10 Jul 2026 11:10:28 +0900 Hajime Tazaki <thehajime@xxxxxxxxx> wrote:

> When shrinking a VMA via mremap, the bounds are modified directly:
> mm/nommu.c:do_mremap() {
> ...
> vma->vm_end = vma->vm_start + new_len;
> ...
> }
> This shrink the VMA without updating its bounds in the maple tree.
> If the maple tree (mm->mm_mt) still contains the old bounds, a user
> process could access the freed portion. The stale maple tree would
> incorrectly return the shrunk VMA for an address past its new vm_end.
>
> This commit fixes this issue by calling vmi_shrink_vma() when shrink
> happens.

Thanks again for helping with NOMMU. I'd like to give you a medal, but
you'll have to settle for an overstuffed inbox.

Sashiko is up to its usual tricks:
https://sashiko.dev/#/patchset/20260710021028.892645-1-thehajime@xxxxxxxxx

I assume that ENOMEM is more likely on NOMMU, and that we should hence be
more defensive about handling it. Seems we have not been.