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=1796324398; b=H9uiu+JGIXt/C3bBMTPJ6FTO7LERaP2SsouJ95wQ2q0A2pKpaxIbg0c08LardJXs4xU/ xKokIhzoDpAFnTZDgBBvFIyoih2qRVM3SLdkWjAYFlbC6fOtzc758kczj/98YFsLhFbY0 1aavL82FhTMiXEe+f2TXFOCB8IkuBbdrykErqBUgxVzOyh/3u8AcPy5B2zJftiymsetK+ /iYn4+gLI4ws8MG+q0ANKNk4UMuPg63naqgtbz4ddBu26rUFgO6cwtgS8GSaeNkZuNKh3 ftEl7Cs3+larCJ7viGrHTgbDMNaQQi8BPyK6AQvCoGg1eDUZ9L6HBmeCb7sgAPIT5aQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796324398; h=Received:DKIM-Signature:Date:To:From:In-Reply-To:References:Subject: Message-Id; bh=PRJvk50h1HI0D9lZ7BIM3im12ERN9pDWf3KgtzoTXqg=; b=CoHzow203GeqguZ665cd0M3qPEt0ccDYWCFSwmPAkSycBVDR2W6bY0LWuKjVjPXKy6Du QQoCm5Oq2AhN83OJxa8XdiRGFJPOuuuFK8PcSEzFjze6r39FiFzewzTCloyrcrWQdtXet HnsMDa8ggdDO4smPG2VcUGo0Rd7Xg913JAHvST/1Lx76RnJOpCBlvdvci8Xke/uYAzuTY woC1x52ybRQ9jN/y2z/qFYrHuKt6fq6KnxTfSDMp8PDA+PC8OOZmeH1MTlyDzae84H94f ExA2sbGvuXzV6k0goGr+1HfCbbcxTLJDAOz3txZsEILLIwz7u6K78/Sjqpd6vDsEhTw== 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=QdGc3oKr; 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 023B0606A322 for ; Thu, 3 Dec 2026 18:59:57 +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=QdGc3oKr Received: by smtp.kernel.org (Postfix) with ESMTPSA id 8679D1F000C1; Thu, 3 Dec 2026 18:59:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1796324397; bh=PRJvk50h1HI0D9lZ7BIM3im12ERN9pDWf3KgtzoTXqg=; h=Date:To:From:In-Reply-To:References:Subject; b=QdGc3oKryIRoP1vuHoRxEES8vDmA0zcr3XyhwaD3VyWc+LjY/DDXNKbSsY0+22VXa 0GJG6vgZQhwU5h1sWHunQNLK+WEckt9CBNfsC76eqFZH0XECWsNHdeoztp/s6E9Urf 5OuTtB6NzfhRZJi86qWmq2G9NVG//ZywB2YrpY4k= Date: Thu, 03 Dec 2026 10:59:57 -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: [to-be-updated] hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch removed from -mm tree Message-Id: <20261203185957.8679D1F000C1@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 quilt patch titled Subject: hugetlbfs: recheck the vma range after the lock wait has been removed from the -mm tree. Its filename was hugetlbfs-recheck-the-vma-range-after-the-lock-wait.patch This patch was dropped because an updated version will be issued ------------------------------------------------------ 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: 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: Jason Gunthorpe Cc: luojiajun Cc: Josef Bacik Cc: Daehyeon Ko <4ncienth@gmail.com> Cc: Ackerley Tng 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 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-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 a.patch