[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <4vhras6zlrv73di2fran4lwk3yhtm4uwgr34oitxvqtdm2j643@cowbnzlcyv2o>
Date: Wed, 16 Oct 2024 12:56:04 -0400
From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
To: Andrew Morton <akpm@...ux-foundation.org>
Cc: linux-mm@...ck.org, linux-kernel@...r.kernel.org,
Jann Horn <jannh@...gle.com>,
Lorenzo Stoakes <lorenzo.stoakes@...cle.com>,
Vlastimil Babka <vbabka@...e.cz>, Matthew Wilcox <willy@...radead.org>,
David Hildenbrand <david@...hat.com>
Subject: Re: [PATCH v2] mm/mmap: Fix race in mmap_region() with ftrucate()
This should have been a hotfix as it needs to go into v6.12
* Liam R. Howlett <Liam.Howlett@...cle.com> [241015 21:35]:
> From: "Liam R. Howlett" <Liam.Howlett@...cle.com>
>
> Avoiding the zeroing of the vma tree in mmap_region() introduced a race
> with truncate in the page table walk. To avoid any races, create a hole
> in the rmap during the operation by clearing the pagetable entries
> earlier under the mmap write lock and (critically) before the new vma is
> installed into the vma tree. The result is that the old vma(s) are left
> in the vma tree, but free_pgtables() removes them from the rmap and
> clears the ptes while holding the necessary locks.
>
> This change extends the fix required for hugetblfs and the call_mmap()
> function by moving the cleanup higher in the function and running it
> unconditionally.
>
> Cc: Jann Horn <jannh@...gle.com>
> Cc: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
> Cc: Vlastimil Babka <vbabka@...e.cz>
> Cc: Matthew Wilcox <willy@...radead.org>
> Cc: David Hildenbrand <david@...hat.com>
> Fixes: f8d112a4e657 ("mm/mmap: avoid zeroing vma tree in mmap_region()")
> Reported-by: Jann Horn <jannh@...gle.com>
> Closes: https://lore.kernel.org/all/CAG48ez0ZpGzxi=-5O_uGQ0xKXOmbjeQ0LjZsRJ1Qtf2X5eOr1w@mail.gmail.com/
> Link: https://lore.kernel.org/all/CAG48ez0ZpGzxi=-5O_uGQ0xKXOmbjeQ0LjZsRJ1Qtf2X5eOr1w@mail.gmail.com/
> Signed-off-by: Liam R. Howlett <Liam.Howlett@...cle.com>
> Reviewed-by: Jann Horn <jannh@...gle.com>
> Reviewed-by: Lorenzo Stoakes <lorenzo.stoakes@...cle.com>
> ---
> mm/mmap.c | 12 +++++++-----
> 1 file changed, 7 insertions(+), 5 deletions(-)
>
> v1: https://lore.kernel.org/all/20241015161135.2133951-1-Liam.Howlett@oracle.com/
>
> Changes since v1:
> Updated commit message - Thanks Lorenzo
>
> diff --git a/mm/mmap.c b/mm/mmap.c
> index dd4b35a25aeb..a20998fb633c 100644
> --- a/mm/mmap.c
> +++ b/mm/mmap.c
> @@ -1413,6 +1413,13 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
> vmg.flags = vm_flags;
> }
>
> + /*
> + * clear PTEs while the vma is still in the tree so that rmap
> + * cannot race with the freeing later in the truncate scenario.
> + * This is also needed for call_mmap(), which is why vm_ops
> + * close function is called.
> + */
> + vms_clean_up_area(&vms, &mas_detach);
> vma = vma_merge_new_range(&vmg);
> if (vma)
> goto expanded;
> @@ -1432,11 +1439,6 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
>
> if (file) {
> vma->vm_file = get_file(file);
> - /*
> - * call_mmap() may map PTE, so ensure there are no existing PTEs
> - * and call the vm_ops close function if one exists.
> - */
> - vms_clean_up_area(&vms, &mas_detach);
> error = call_mmap(file, vma);
> if (error)
> goto unmap_and_free_vma;
> --
> 2.43.0
>
Powered by blists - more mailing lists