From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AADFA393DCA for ; Fri, 12 Jun 2026 16:12:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781280740; cv=none; b=ZDR3nARRgFSuy4xT6i2aO8aj+4faaUP5KxDKTxMlizJUWcLtON11/SKcAc4u7sXz9clK1au0RMxA0Z0qbcyhnnSNZQRCHDGJ1LKS0ai+xWNPm6eahlIPPYwFJrBCkIXNDs1H+wigA4bv8TJsqfMW0Pgks9GedfFv2nnzUP7IBtU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1781280740; c=relaxed/simple; bh=mjSFyYQU8XVImuAvpcpFvMzY57hl+keQLof3W/655wQ=; h=Date:From:To:Cc:Subject:Message-Id:In-Reply-To:References: Mime-Version:Content-Type; b=oXrnd1DPevMJp/L/tSrAdvuWOkA7Dgn9hnCahCWHzLcNEOHxge2SY8qJ7TWwENwbpeDmePr6vYPbG/fo7iSI+Hc5k4i8+CSbIFZau/AI+f8FXVknId2PqCjrrqYyhqmvD/BhsFgKYg1l0fqI9WCAV9SRHWZZ4KArqc9VxZ6yG+0= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b=jZpBlWZy; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux-foundation.org header.i=@linux-foundation.org header.b="jZpBlWZy" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 805291F000E9; Fri, 12 Jun 2026 16:12:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux-foundation.org; s=korg; t=1781280736; bh=/sPiD+QHAE5SnG3mf+RwozqEbzxycx4/mCbYbChQOc8=; h=Date:From:To:Cc:Subject:In-Reply-To:References; b=jZpBlWZyiTJBePPX3uSESMJtoiH8kYT9JooRHuu0lO1UDNgPQnnL5p0Zpgv5Zleqv pByhksc/sOnjgM9UVL79PRLmRnBLClOZ/tMZd8tx65Y4bG1rrItOSbtijIBrG5hJuH IkxtwFr7fonxu+of4lJ5DwdfESzjWMSTiHhfjWX0= Date: Fri, 12 Jun 2026 09:12:15 -0700 From: Andrew Morton To: David Carlier Cc: syzbot+fd95a72470f5a44e464c@syzkaller.appspotmail.com, David Hildenbrand , Lorenzo Stoakes , "Liam R. Howlett" , Vlastimil Babka , Mike Rapoport , Suren Baghdasaryan , Michal Hocko , Lu Baolu , Dave Hansen , linux-mm@kvack.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2] mm: pgtable: protect lockless kernel page table walks with RCU Message-Id: <20260612091215.b06dc7dc9dc894a5bfc75429@linux-foundation.org> In-Reply-To: <20260612050540.31594-1-devnexen@gmail.com> References: <20260612050540.31594-1-devnexen@gmail.com> X-Mailer: Sylpheed 3.8.0beta1 (GTK+ 2.24.33; x86_64-pc-linux-gnu) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit On Fri, 12 Jun 2026 06:05:40 +0100 David Carlier wrote: > ptdump walks the kernel page tables locklessly through > walk_kernel_page_table_range_lockless(). It only holds the init_mm > mmap lock and the memory hotplug lock, and neither excludes > vmalloc/ioremap teardown from freeing kernel PTE pages via > pmd_free_pte_page() -> pagetable_free_kernel(). syzbot hit a > use-after-free in ptdump_pte_entry() reading a PTE page that was freed > underneath the walk. > > Deferring the kernel page table free only batches the TLB flush; it does > not wait for lockless walkers. Mirror the user page table walk, where > pte_offset_map() already takes the RCU read lock: hold rcu_read_lock() > across the lockless kernel walk and rcu-free the page tables in the > kernel page table free worker, after the batched TLB flush. A walker > then either observes the cleared PMD and skips the page, or keeps it > alive until it drops the RCU read lock. > > ... > > --- a/mm/pagewalk.c > +++ b/mm/pagewalk.c > @@ -655,13 +655,26 @@ int walk_kernel_page_table_range_lockless(unsigned long start, unsigned long end > .private = private, > .no_vma = true > }; > + int err; > > if (start >= end) > return -EINVAL; > if (!check_ops_safe(ops)) > return -EINVAL; > > - return walk_pgd_range(start, end, &walk); > + /* > + * Kernel intermediate page tables can be freed concurrently by > + * vmalloc/ioremap teardown (e.g. pmd_free_pte_page()), which routes > + * the freed pages through pagetable_free_kernel(). That path defers > + * the free past an RCU grace period, so hold the RCU read lock across > + * the lockless walk to prevent a page table from being freed while we > + * are still dereferencing it. > + */ > + rcu_read_lock(); > + err = walk_pgd_range(start, end, &walk); > + rcu_read_unlock(); > + > + return err; > } Adding a lock to a function which is advertised to "walk the kernel page tables locklessly" is a bit of a head-spinner. Sashiko claims that some callback functions can perform sleeping allocations: https://sashiko.dev/#/patchset/20260612050540.31594-1-devnexen@gmail.com