Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=115.124.30.111 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796377104; b=ZqcAm7jO0EZm2cKrvs1jmS0TXd8gPSaW9gGp38eZR+geJGcUGSqFjs0R9RQbLgC9OXZj w3e6II7Vh0BtOV88Tsldt+lyyNSoLrG2uiPLymqyKgL9qCuVhA4nbx42aXHzIO9m9akRU SyKMS3YHd+OkIFgMbgTt7uO4lRfXQGiKthxEQ/vr0CJjldACIaVSYwWfDOzPPjfUlX4HF T8mpLHGSZZeNFXlrYf3akgZ+R5RYYyDXDOOPkqpirukm9d0ShvtFeApdveaPeO0eq6yUs jx9991GdGngPLTlYURTl8q1f8pjBMTlj9O8xD8Ec+shMtUrHiXhWot86ifxYYEhef5w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796377104; h=DMARC-Filter:DKIM-Signature:X-Alimail-AntiSpam:Received:Message-ID: Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: In-Reply-To:Content-Type:Content-Transfer-Encoding; bh=O8KqoLkl67O15YLOTnW51nCORjsF+tsR1pI5HyEhxlM=; b=A4CCT0jPianNJGWU32I0ERNK9cOEnEFwKq7naqf30wIJsELJF1hVgnbxPHESI+2acUEs sfd4K4NItJ2BHtvACt1SxmTqYNPwk8t5Wmk/3PhGLf8gKqSOulUFvqxOR2ilx7vjHMzsZ 5Sb8EACm0/cFWg1L9mmVmMt84nnDsAkL9/0W56vrHmxKVF4Sy+TRezqkwfMbp69jEvN6N q6nx15KM5kEqS+OJNcfX9wC4QzfM12/TGgtzc7AObWvVNgYjMSPxhtvkM5xLFKEm6E4+s h/rNfpbJLs+HhEg3hPaKP/m99kJn6Lg+EFqEmr2lMlOnpmpdSzZaC4JHOyBwMy0Kc3Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=linux.alibaba.com; spf=pass smtp.mailfrom=linux.alibaba.com; dkim=pass header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=WaxweAey; arc=none smtp.remote-ip=115.124.30.111 Received: from out30-111.freemail.mail.aliyun.com (out30-111.freemail.mail.aliyun.com [115.124.30.111]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C8F7F606A322 for ; Fri, 4 Dec 2026 09:38:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org C8F7F606A322 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.alibaba.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key, unprotected) header.d=linux.alibaba.com header.i=@linux.alibaba.com header.a=rsa-sha256 header.s=default header.b=WaxweAey DKIM-Signature:v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.alibaba.com; s=default; t=1796377100; h=Message-ID:Date:MIME-Version:Subject:To:From:Content-Type; bh=O8KqoLkl67O15YLOTnW51nCORjsF+tsR1pI5HyEhxlM=; b=WaxweAeyW1X1HfzAtGoAR5KkK9t69rFHRPxo5K4xCtUawD2Vjzwga61HBd9y26jgtQm6McXNGaqklYo/zWnzTrdw2agD/DwJZVqaQ5Pg/Uw+HOjZDVRyt2qrrMUYtjfoX8cEnUtXsWyepLi9TNyBrGA8AujVLvDt+ubOOqRAmqs= X-Alimail-AntiSpam:AC=PASS;BC=-1|-1;BR=01201311R311e4;CH=green;DM=||false|;DS=||;FP=0|-1|-1|-1|0|-1|-1|-1;HT=maildocker-contentspam033045144198;MF=baolin.wang@linux.alibaba.com;NM=1;PH=DS;RN=22;SR=0;TI=SMTPD_---0XGGtaio_1796377096; Received: from 30.74.144.139(mailfrom:baolin.wang@linux.alibaba.com fp:SMTPD_---0XGGtaio_1796377096 cluster:ay36) by smtp.aliyun-inc.com; Fri, 04 Dec 2026 17:38:18 +0800 Message-ID: Date: Fri, 4 Dec 2026 17:38:15 +0800 X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v2 7/9] mm/huge_memory: avoid transient none PMDs during lazyfree reclaim To: Zi Yan , David Hildenbrand , "Liam R. Howlett" , Nico Pache , Ryan Roberts , Dev Jain , Barry Song , Lance Yang , Usama Arif , Kiryl Shutsemau , Lorenzo Stoakes , Rik van Riel , Vlastimil Babka , Harry Yoo , Jann Horn , Kyle Zeng , Andrew Morton Cc: linux-mm@kvack.org, linux-kernel@vger.kernel.org, John Hubbard , Peter Xu , Jason Gunthorpe References: <20261203-anon_vma_uaf_fix-v2-0-3d4c746e8839@nvidia.com> <20261203-anon_vma_uaf_fix-v2-7-3d4c746e8839@nvidia.com> From: Baolin Wang In-Reply-To: <20261203-anon_vma_uaf_fix-v2-7-3d4c746e8839@nvidia.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit On 12/4/26 12:17 PM, Zi Yan wrote: > From: Kyle Zeng > > __discard_anon_folio_pmd_locked() clears and flushes a huge PMD before > checking whether the folio can be discarded. If the folio was redirtied > or has unexpected references, it restores the original PMD. Reclaim holds > the PMD lock and the anon_vma read lock, but not the owning mmap_lock. > > Both zap_pmd_range() and mremap's get_old_pmd() can skip a none PMD > without taking its lock. A concurrent munmap() or whole-VMA > MREMAP_DONTUNMAP can therefore miss the PMD and later unlink the source > VMA from its anon_vma, leaving a restored mapping behind. The anon_vma > write lock taken by unlink_anon_vmas() waits for reclaim to finish, but > does not repeat the skipped page-table walk. Once the remaining VMA > links are removed, the folio's positive mapcount no longer guarantees a > live anon_vma. Racing lazyfree reclaim against MREMAP_DONTUNMAP as an > unprivileged user reproduces a KASAN use-after-free in > folio_lock_anon_vma_read(). > > Use pmdp_invalidate() to keep a recognizable, non-none huge PMD while > the discard can still fail. Concurrent unmap and move operations then > have to synchronize on the PMD lock instead of skipping the mapping. > Clear the invalidated PMD only after the dirty and reference checks have > succeeded, before removing the rmap and withdrawing the deposited page > table. The full invalidation retains the TLB flush required for the > dirty and GUP-fast checks. > > Signed-off-by: Kyle Zeng > Signed-off-by: Zi Yan > To: Andrew Morton > To: David Hildenbrand > To: Lance Yang > Cc: Zi Yan > Cc: Baolin Wang > Cc: "Liam R. Howlett" > Cc: Nico Pache > Cc: Ryan Roberts > Cc: Dev Jain > Cc: Barry Song > Cc: Usama Arif > Cc: Kiryl Shutsemau > Cc: Jason Gunthorpe > Cc: John Hubbard > Cc: Peter Xu > Cc: linux-mm@kvack.org > Cc: linux-kernel@vger.kernel.org > --- Make sense to me. Reviewed-by: Baolin Wang