From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796325231; b=l8a3PDcgpnDqkeeA4OFo+lA0lHXqxKRaXS/T9rg4z5dmkq2NrmlXSHH8NVuckFSLnAE4 KLgsioWMEJ4Oj6gTRdKF5MZYz/PYg0PDlqSMxMtMzA6DrEO2Ff4H9TbYMGq9MoHe4j7Oz 9AlFXKBqpciHIgEKGDfL4SoIUAde8Cs2rbTgg6MmLwhdcLcpCBxL3fxSrCQHM9CYHbU6T gO2wqjSFSJw0Y9IllxUIufFbDsqBXFTMZVrXtMYilg5MgWLm7xgrorpeDl06bgYFw0i+R s6oTj2MpC2bKtAoXLiCaHOiAGMENiOq10Fx2NuUm8cigHknnVV2UyIFVtotTuLdVj0w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796325231; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=TtI+U+XxTmanvRa8DcZDLCWdXTG9jIgMpVfN8Acvde4=; b=qOoAOGtaGlj1xVMLrerjUfwbBsCcmbzD1TV9/Uu/dHSn1voZ8rrwRKMmhRLYh7TTYba6 ZSrv4Mb6D5IlaSjKXxrL4BwOO19s72yAgSLNbyrM+PuSRYjd8hlAng8esTVYn6zsSOi55 NYq2//VBi33piKZjtF1IItVi1zwDiqPwaxsIvkjwZer6Z4bR4i1nuW6Oq9ACihTdKPVIW HVjdxYxfVFiIMXtBj506+vroUvX3KfNla5xGrT7GwZeP4XoGqzQQvZ7nQfp8HKqVJaf09 fvbO9mlBzXtrWvR7WpdzKvVS976hurNJNn6+LYotaBq5Cy+HsTK//3+E02ACW0hTcSA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Ld3GSALy; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 47D82606A322 for ; Thu, 3 Dec 2026 19:13:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.a=rsa-sha256 header.s=korg header.b=Ld3GSALy Received: by smtp.kernel.org (Postfix) with ESMTPSA id D7ADD1F000C2; Thu, 3 Dec 2026 19:13:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796325231; bh=TtI+U+XxTmanvRa8DcZDLCWdXTG9jIgMpVfN8Acvde4=; h=Date:To:From:In-Reply-To:References:Subject; b=Ld3GSALy0z02LPSPrEDicC/CH5l9v19J5vTR1znImuPD9tMomUastRIzvgINlCVdp ZsGE+8n8jYgB4JrTy6xu02XCgIFnu/GaKtxWJ9+EVYQvTGjLcoLaLlBX7feAy4useQ 7yMUsBXsdDpoGE8MkoEshbiU8OusS9ajJfsjQslY= Date: Thu, 03 Dec 2026 11:13:50 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261203-hugetlb_fixes_2-v2-19-9bbeabb555d2@kernel.org> References: <20261203-hugetlb_fixes_2-v2-19-9bbeabb555d2@kernel.org> Subject: + hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch added to mm-unstable branch Message-Id: <20261203191350.D7ADD1F000C2@smtp.kernel.org> X-Mailing-List: mm-commits@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list The patch titled Subject: hugetlbfs: recheck the vma range after the lock wait has been added to the -mm mm-unstable branch. Its filename is hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch This patch will shortly appear at https://git.kernel.org/pub/scm/linux/kernel/git/akpm/25-new.git/tree/patches/hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch This patch will later appear in the mm-unstable branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Before you just go and hit "reply", please: a) Consider who else should be cc'ed b) Prefer to cc a suitable mailing list as well c) Ideally: find the original patch on the mailing list and do a reply-to-all to that, adding suitable additional cc's *** Remember to use Documentation/process/submit-checklist.rst when testing your code *** The -mm tree is included into linux-next via various branches at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm and is updated there most days ------------------------------------------------------ From: Chris Mason Subject: hugetlbfs: recheck the vma range after the lock wait Date: Thu, 03 Dec 2026 12:37:42 +0100 A hole punch or a truncation of a hugetlb file that races with a split of a shared vma can lead to a use-after-free read of a page table, and to an MMU notifier range with end <= start, which trips a WARN_ON_ONCE() in KVM. hugetlb_unmap_file_folio() computes the address of the folio in a vma and walks the page tables to unmap the folio. As free_pgtables() unlinks a vma from the rmap tree before it frees its page tables, i_mmap_rwsem does not protect page tables outside of the vma, so walking them can result in a use-after-free read. The rmap tree walk guarantees that a found vma spans our folio. However, when we have to fall back to locking the vma lock first and drop the i_mmap_rwsem, we don't check whether that is still the case after we acquired the vma lock and the i_mmap_rwsem. The following is then possible: hugetlb_unmap_file_folio() __split_vma(), new_below == 0 ========================== ============================= hugetlb_vma_trylock_write() fails i_mmap_unlock_write() down_write(&vma_lock->rw_sema) vma_prepare() i_mmap_lock_write() vma->vm_end = addr vma_complete() i_mmap_unlock_write() i_mmap_lock_write() vma_lock->vma is not NULL vma_offset_start() >= vma->vm_end vma_offset_end() == vma->vm_end hugetlb_vma_maps_pfn(vma, v_start) unmap_hugepage_range(vma, v_start, v_end) Similarly, a split with new_below == 1, where the vma keeps the upper part and vm_start and vm_pgoff move up, or shrinking the vma with mremap() can leave the vma not covering our folio. Let's fix it by checking whether the possibly split vma still spans our folio. Add a VM_WARN_ON_ONCE() to highlight the problem that was previously missed. This has medium urgency, as this is triggerable by unprivileged users. [david@kernel.org: adjust comment and description] Link: https://patch.msgid.link/20261203-hugetlb_fixes_2-v2-19-9bbeabb555d2@kernel.org Fixes: 40549ba8f8e0 ("hugetlb: use new vma_lock for pmd sharing synchronization") Signed-off-by: Chris Mason Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Cc: Muchun Song Cc: Oscar Salvador Cc: Hongfu Li Cc: Jinmeng Zhou Cc: Mina Almasry Cc: Davidlohr Bueso Cc: Naoya Horiguchi Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Mike Rapoport Cc: Michal Hocko Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Vivek Kasireddy Cc: Mel Gorman Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Jason Gunthorpe Cc: Andy Whitcroft Cc: Roman Gushchin Cc: Barry Song Cc: Andrea Arcangeli Cc: Lorenzo Stoakes Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato Cc: Jann Horn Cc: Guillaume Morin Cc: Yang Shi Cc: James Houghton Cc: Rik van Riel Cc: Harry Yoo Cc: Lance Yang Cc: Axel Rasmussen Cc: Peter Xu Cc: Sasha Levin Cc: Kiryl Shutsemau Cc: Christian Brauner Cc: Steven Rostedt Cc: Hongbo Li Cc: Gregory Price Cc: Zi Yan Cc: Joshua Hahn Cc: Rakie Kim Cc: Ying Huang Cc: Matthew Brost Cc: Byungchul Park Cc: Alistair Popple Cc: Andi Kleen Cc: David Rientjes Cc: Joern Engel Cc: Aneesh Kumar K.V Cc: Gerd Hoffmann Cc: Johannes Weiner Cc: Jiaqi Yan Cc: fs/hugetlbfs/inode.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) --- a/fs/hugetlbfs/inode.c~hugetlbfs-recheck-the-vma-range-after-the-lock-wait +++ a/fs/hugetlbfs/inode.c @@ -439,10 +439,11 @@ retry: i_mmap_lock_write(mapping); vma = vma_lock->vma; - if (!vma) { + if (!vma || vma_start_pgoff(vma) >= end || vma_end_pgoff(vma) <= start) { /* - * If lock is no longer attached to vma, then just - * unlock, drop our reference and retry looking for + * If the lock is no longer attached to this vma, or if + * the vma changed and no longer covers the folio, then + * just unlock, drop our reference and retry looking for * other vmas. */ up_write(&vma_lock->rw_sema); @@ -456,6 +457,7 @@ retry: */ v_start = vma_offset_start(vma, start); v_end = vma_offset_end(vma, end); + VM_WARN_ON_ONCE(v_start >= v_end); if (hugetlb_vma_maps_pfn(vma, v_start, pfn)) unmap_hugepage_range(vma, v_start, v_end, NULL, ZAP_FLAG_DROP_MARKER); _ Patches currently in -mm which might be from mason@kernel.org are mm-swap-fix-large-swap-in-across-swap-file-extents.patch hugetlbfs-do-not-grow-a-sealed-file-in-mmap.patch mm-hugetlb-keep-surplus-folios-that-are-reserved.patch mm-hugetlb-fix-reservation-leak-on-min_size=-mounts.patch mm-cachestat-count-each-page-only-once.patch mm-cachestat-restart-the-walk-after-each-entry.patch percpu-queue-the-balance-work-on-an-unbound-workqueue.patch mm-vma-fix-uncharge-after-failed-stack-relocation.patch mm-mremap-apply-the-mmap-offset-limits-on-expansion.patch mm-mremap-respect-guard-gaps-on-in-place-expansion.patch mm-vma-make-brk-mappings-non-executable-under-mdwe.patch kfence-use-a-nofault-store-to-zero-the-guard-page.patch mm-filemap-update-the-folio-order-range-atomically.patch mm-userfaultfd-account-memory-allocated-for-unmap-events.patch mm-userfaultfd-drop-fork-context-reference-outside-event_wqhlock.patch mm-madvise-dont-declare-oom-for-madv_willneed-swapin.patch mm-mprotect-fix-unpaired-notifier-start-at-address-0.patch mm-hmm-refuse-secretmem-vmas-in-hmm_range_fault.patch mm-mglru-count-all-generations-as-evictable.patch mm-mglru-test-pg_lru-before-taking-a-folio-reference.patch mm-mglru-report-root-reclaim-to-memorypressure_level.patch mm-hugetlb-fix-truncated-copy-result-in-uffdio_copy.patch hugetlbfs-fix-deadlock-between-hole-punching-and-memory-failure.patch hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch mm-hugetlb-dont-zap-non-present-entries-when-unmapping-a-folio.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch