Re: [PATCH] mm/mremap: correctly uncharge accountable VMAs in error path
From: Liam R. Howlett
Date: Mon Nov 16 2026 - 13:19:56 EST
On 26/10/19 04:57PM, Lorenzo Stoakes (ARM) wrote:
> The mremap error path is a fragile and unwieldy beast - it reverses the
> page table move then updates vma_remap_struct state to swap VMA, length and
> address between old and new VMAs in copy_vma_and_data().
>
> If the mremap() operation didn't specify MREMAP_DONTUNMAP then its caller,
> move_vma(), invokes unmap_source_vma(), which unmaps the new VMA rather
> than the old one.
>
> For accountable VMAs when MREMAP_DONTUNMAP is not specified,
> unmap_source_vma() unsets VMA_ACCOUNT_BIT during this unmap in order that
> only the delta of a VMA expansion is charged (performed by
> vrm_calc_charge() earlier).
>
> Therefore nothing uncharges the expanded VMA size, and there is a permanent
> leak in global Committed_AS.
>
> Resolve the issue by uncharging when MREMAP_DONTUNMAP is not specified.
>
> Fixes: fdbef6149135 ("mm/mremap: don't account pages in vma_to_resize()")
> Cc: stable@xxxxxxxxxxxxxxx
> Signed-off-by: Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
Reviewed-by: Liam R. Howlett (Google) <liam@xxxxxxxxxxxxx>
> ---
> Issue was found when I had local AI check the other mremap() fix from today - it
> raised that this pre-existing issue was present.
> ---
> mm/mremap.c | 14 ++++++++++++++
> 1 file changed, 14 insertions(+)
>
> diff --git a/mm/mremap.c b/mm/mremap.c
> index 6970783fc445..1620006028c4 100644
> --- a/mm/mremap.c
> +++ b/mm/mremap.c
> @@ -1338,6 +1338,20 @@ static int copy_vma_and_data(struct vma_remap_struct *vrm,
> pmc_revert.need_rmap_locks = true;
> move_page_tables(&pmc_revert);
>
> + /*
> + * When copy_vma_and_data() returns, the new VMA will be
> + * unmapped rather than the old one.
> + *
> + * When an accountable move is being performed, this unmapping
> + * will not uncharge any expansion, so do that now.
> + *
> + * A move is accountable if the VMA is accountable and
> + * MREMAP_DONTUNMAP is not specified, so only do so if the
> + * latter is true.
> + */
> + if (!(vrm->flags & MREMAP_DONTUNMAP))
> + vrm_uncharge(vrm);
> +
> vrm->vma = new_vma;
> vrm->old_len = vrm->new_len;
> vrm->addr = vrm->new_addr;
>
> ---
> base-commit: 4dbe24720eb3811563cd56b35d87ddf3f9beed2a
> change-id: 20261019-other-mremap-charge-leak-b426336c0299
>
> Cheers,
> --
> Lorenzo Stoakes (ARM) <ljs@xxxxxxxxxx>
>