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=1796007127; b=Px4D6R/cDzoPwhF8zwASTLvebeqdieT0PWe4GHC4qanRxhWNc1mYvX0MYzujjuwg3kLN PVw0dN+DHTyJarSPeFVu5Nul06bpuOQWjS3bjOeheVmjiv4TKfVWjam70ND3AlJbAb1Wd Baz4YM2wnpu2pTlyvZ3kva1ZFlCmUG6MCvccuiLGnwUhoJxPXuR/mIXAok7ADlzGeBJKH YfMEz7AGDGXP4264QhfMdLV8PR4NcHtganJUC655+kuFzM/ZNVe8ZYaoxa75MZuzPDqWJ UaTyMER+I1Y7UNMYuWMhGT+J9xLLEHaWBVa+qk/VAioKMkbctbze2zf6pASqLzSMKtw== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796007127; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=e3SRL2NxxT+8YVeI3ZyPiLe0CSuirUFFvz9D2eetI6k=; b=df7WLw+2QUaz66k9iANZRPL8jFwTVHMvcA+4tDPludUfSSqp/N6CvcO8sSU1gWRqjs46 GiRcW+W8clDNR4dMHjA42JsKcSf0oKh8Axp7VfwaP67nK7lZhEeUTdp44HjM/yvd6r081 eZ33NfwhpfscC+OWIxjeQnRfz5gcJOH1LmclH18xNvaBVop0Eea8eZqzq3z3TZRhUs2vd QuChOZOUIwTdkgCqr7ZUgysHIfj1x219K/se90Nuidc/9lKF3jfpUH6d7/bdstl3yKrJt vTo8C8p57zEVdhYisaG7Di5c6496DazA5OEtj1IEN2ebqvvX0Y1hWHAR8Q5sQcP0OYg== 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=X1YugyQV; 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 BDFDD606A31C for ; Mon, 30 Nov 2026 02:52:07 +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=X1YugyQV Received: by smtp.kernel.org (Postfix) with ESMTPSA id 1A99D1F00897; Mon, 30 Nov 2026 02:52:07 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796007127; bh=e3SRL2NxxT+8YVeI3ZyPiLe0CSuirUFFvz9D2eetI6k=; h=Date:To:From:In-Reply-To:References:Subject; b=X1YugyQVgYl5jDnZsABJ+iRh3U4thGuZii7oCcTmtPPaLCOfOnSScA3YnTN/79vTP kIJPvbz/XEYoNqATWPA6io70rnxhWQtGDM3rKZhH49x4/jP7SHufG+qnO3pxqiGpIG qif4r5txTvAPicd9pRRogcIb38JSziUcyAinGWsc= Date: Sun, 29 Nov 2026 18:52:06 -0800 To: mm-commits@vger.kernel.org,mason@kernel.org,akpm@linux-foundation.org From: Andrew Morton In-Reply-To: <20261125-hugetlb_fixes_2-v1-8-db27fd2f71a8@kernel.org> References: <20261125-hugetlb_fixes_2-v1-8-db27fd2f71a8@kernel.org> Subject: + hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch added to mm-new branch Message-Id: <20261130025207.1A99D1F00897@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-new 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-new branch at git://git.kernel.org/pub/scm/linux/kernel/git/akpm/mm Note, mm-new is a provisional staging ground for work-in-progress patches, and acceptance into mm-new is a notification for others take notice and to finish up reviews. Please do not hesitate to respond to review feedback and post updated versions to replace or incrementally fixup patches in mm-new. The mm-new branch of mm.git is not included in linux-next If a few days of testing in mm-new is successful, the patch will me moved into mm.git's mm-unstable branch, which is included in linux-next 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: Wed, 25 Nov 2026 23:33:06 +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/20261125-hugetlb_fixes_2-v1-8-db27fd2f71a8@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: Jinmeng Zhou Cc: Hongfu Li Cc: Andrea Arcangeli Cc: Mike Kravetz Cc: Naoya Horiguchi Cc: Hugh Dickins Cc: Baolin Wang Cc: Dave Airlie Cc: Vivek Kasireddy Cc: Gerd Hoffmann Cc: Mike Rapoport Cc: Mel Gorman Cc: Dave McCracken Cc: Andy Whitcroft Cc: Adam Litke Cc: Lorenzo Stoakes Cc: Rik van Riel Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Harry Yoo Cc: Jann Horn Cc: Lance Yang Cc: James Houghton Cc: Yang Shi Cc: Suren Baghdasaryan Cc: Shakeel Butt Cc: Pedro Falcato 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: Wanpeng Li Cc: Andi Kleen Cc: Kenneth W Chen Cc: Michal Hocko Cc: David Rientjes Cc: Joern Engel Cc: Jonathan Corbet Cc: Shuah Khan Cc: Randy Dunlap Cc: Aneesh Kumar K.V Cc: KAMEZAWA Hiroyuki Cc: Kiryl Shutsemau Cc: Sasha Levin Cc: Guillaume Morin Cc: Wanpeng Li Cc: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng Cc: "Oscar Salvador (SUSE)" 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 @@ -442,10 +442,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); @@ -459,6 +460,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 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 kfence-use-a-nofault-store-to-zero-the-guard-page.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 mm-hugetlb-unshare-pmds-of-a-split-vma-if-allocating-its-lock-fails.patch mm-hugetlb_cgroup-track-in-use-folios-per-cgroup.patch hugetlbfs-seal-shm_hugetlb-files-against-growth.patch mm-hugetlb-resolve-protnone-faults-without-a-uffd-bit.patch