lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <19dad66f-4ec8-358c-df7f-35481f855c81@redhat.com>
Date:   Wed, 5 Apr 2023 17:54:46 +0200
From:   David Hildenbrand <david@...hat.com>
To:     Peter Xu <peterx@...hat.com>, linux-mm@...ck.org,
        linux-kernel@...r.kernel.org
Cc:     Axel Rasmussen <axelrasmussen@...gle.com>,
        Nadav Amit <nadav.amit@...il.com>,
        Andrew Morton <akpm@...ux-foundation.org>,
        Andrea Arcangeli <aarcange@...hat.com>,
        Mike Rapoport <rppt@...ux.vnet.ibm.com>,
        Yang Shi <shy828301@...il.com>,
        linux-stable <stable@...r.kernel.org>
Subject: Re: [PATCH] mm/khugepaged: Check again on anon uffd-wp during
 isolation

On 05.04.23 17:51, Peter Xu wrote:
> Khugepaged collapse an anonymous thp in two rounds of scans.  The 2nd round
> done in __collapse_huge_page_isolate() after hpage_collapse_scan_pmd(),
> during which all the locks will be released temporarily. It means the
> pgtable can change during this phase before 2nd round starts.
> 
> It's logically possible some ptes got wr-protected during this phase, and
> we can errornously collapse a thp without noticing some ptes are
> wr-protected by userfault.  e1e267c7928f wanted to avoid it but it only did
> that for the 1st phase, not the 2nd phase.
> 
> Since __collapse_huge_page_isolate() happens after a round of small page
> swapins, we don't need to worry on any !present ptes - if it existed
> khugepaged will already bail out.  So we only need to check present ptes
> with uffd-wp bit set there.
> 
> This is something I found only but never had a reproducer, I thought it was
> one caused a bug in Muhammad's recent pagemap new ioctl work, but it turns
> out it's not the cause of that but an userspace bug.  However this seems to
> still be a real bug even with a very small race window, still worth to have
> it fixed and copy stable.
> 
> Cc: linux-stable <stable@...r.kernel.org>
> Fixes: e1e267c7928f ("khugepaged: skip collapse if uffd-wp detected")
> Signed-off-by: Peter Xu <peterx@...hat.com>
> ---
>   mm/khugepaged.c | 4 ++++
>   1 file changed, 4 insertions(+)
> 
> diff --git a/mm/khugepaged.c b/mm/khugepaged.c
> index a19aa140fd52..42ac93b4bd87 100644
> --- a/mm/khugepaged.c
> +++ b/mm/khugepaged.c
> @@ -575,6 +575,10 @@ static int __collapse_huge_page_isolate(struct vm_area_struct *vma,
>   			result = SCAN_PTE_NON_PRESENT;
>   			goto out;
>   		}
> +		if (pte_uffd_wp(pteval)) {
> +			result = SCAN_PTE_UFFD_WP;
> +			goto out;
> +		}
>   		page = vm_normal_page(vma, address, pteval);
>   		if (unlikely(!page) || unlikely(is_zone_device_page(page))) {
>   			result = SCAN_PAGE_NULL;

Yes, I agree that would be a small race where it could happen.

Reviewed-by: David Hildenbrand <david@...hat.com>

-- 
Thanks,

David / dhildenb

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ