[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <Z1B_kl7YZ4DBX7yP@x1n>
Date: Wed, 4 Dec 2024 11:13:06 -0500
From: Peter Xu <peterx@...hat.com>
To: David Hildenbrand <david@...hat.com>
Cc: linux-kernel@...r.kernel.org, linux-mm@...ck.org,
Muchun Song <muchun.song@...ux.dev>,
Andrew Morton <akpm@...ux-foundation.org>,
Guillaume Morin <guillaume@...infr.org>
Subject: Re: [PATCH v1] mm/hugetlb: don't map folios writable without
VM_WRITE when copying during fork()
On Wed, Dec 04, 2024 at 04:31:00PM +0100, David Hildenbrand wrote:
> If we have to trigger a hugetlb folio copy during fork() because the anon
> folio might be pinned, we currently unconditionally create a writable
> PTE.
>
> However, the VMA might not have write permissions (VM_WRITE) at that
> point.
>
> Fix it by checking the VMA for VM_WRITE. Make the code less error prone
> by moving checking for VM_WRITE into make_huge_pte(), and letting
> callers only specify whether we should try making it writable.
>
> A simple reproducer that longter-pins the folios using liburing to then
> mprotect(PROT_READ) the folios befor fork() [1] results in:
>
> Before:
> [FAIL] access should not have worked
>
> After:
> [PASS] access did not work as expected
>
> [1] https://gitlab.com/davidhildenbrand/scratchspace/-/raw/main/reproducers/hugetlb-mkwrite-fork.c
>
> This is rather a corner case, so stable might not be warranted.
>
> Fixes: 4eae4efa2c29 ("hugetlb: do early cow when page pinned on src mm")
> Cc: Muchun Song <muchun.song@...ux.dev>
> Cc: Andrew Morton <akpm@...ux-foundation.org>
> Cc: Peter Xu <peterx@...hat.com>
> Cc: Guillaume Morin <guillaume@...infr.org>
> Signed-off-by: David Hildenbrand <david@...hat.com>
Acked-by: Peter Xu <peterx@...hat.com>
Thanks,
--
Peter Xu
Powered by blists - more mailing lists