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=1794063626; b=FVSYATsIdMOxN5WiJZBxjtRce0L7tJz7/kTVIxV5d/848oVW10TSOs41G+DfFK+vxkrT VjvGGFeR+YETgIMqUiIZrbudCfnMNW081BFWBDkJz3BmkVOlycw2hAVgy3kxv683+fUf3 BcDgYVzJiD7pxcvw94qiFsTolFa5cUPyJIRwNk9SFX/kYMgd9HqKvWJ1f0oZVxHahSEeT Vx+ftJuUddMMSzcoxmS1lHuQZoHXvjFPZ3Fq11Og5vllAqI9NQ7dYVND4w8+BqCS20F7Q Jpnt4sm9Qi5V+wnsfFlB6zvz0R4kthxv5UXmqoyhN+yJVJdUZZKSRMrj0e6nXWOmvDQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1794063626; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=ZWAXOumCFwczrMWOP4ImlEW7R7AmMzXnyKhOqwa7JuU=; b=NzGluHPOjV+6nSzmXkIS8S8P5QY5CKWJEv5HWlkvc7gF4IKI62FhxUBugUM0mROOeS6T y8CzTJduDPqBb4/GOAGpWDNK0YUcGTrDnJ5aeaiAlllOaaDS1elCzf7n26WXLBszubGRc sNEzMyOfC2mPRh3wPYojczo3t9xfSkYwXPeJC9oIIDsC+J2r986+P9o4XwWdsabJo3Dzd 1CqhcC24nlDtyH5STgdm0MJPtvXrkROv6zb4Gt2EzyIQbEs4gBsWZ7hfdp7yVhOuuWpoj tW78bXwuUW/lllKvjoK2FSWDbXaI2wl8/R+RkwA4SqN2utK1nLwrdXoL5LV1u62qg6Q== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XugMcdom; 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 E762F606A333; Sat, 7 Nov 2026 15:00:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=XugMcdom Received: by smtp.kernel.org (Postfix) with ESMTPSA id 83CB31F0089F; Sat, 7 Nov 2026 15:00:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1794063625; bh=ZWAXOumCFwczrMWOP4ImlEW7R7AmMzXnyKhOqwa7JuU=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=XugMcdomc4S9Ikhrt2XkFmN79C9y9Iyr5A6YkYPwzHRmJd1Hu9PiJbnviOoBoSOwb qHvqIDh3s2jgs0Xye/rFfeLG/AFcfqyVBgbnEY739Ce9UxVnqAxhb8dB9AIK2Fd86t DyxJT/ZfKofov2FYg9Z032T6COaGu9El94LhDJag= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, "David Hildenbrand (Arm)" , Andrew Morton , syzbot+49b1021becba70c1f3f6@syzkaller.appspotmail.com, Nguyen Ngoc Thang , "Lorenzo Stoakes (ARM)" , "Mike Rapoport (Microsoft)" , Lance Yang , "Liam R. Howlett" , Vlastimil Babka , Suren Baghdasaryan , Michal Hocko , Benjamin Herrenschmidt , Peter Zijlstra , Rik van Riel , Sasha Levin Subject: [PATCH 6.18 744/869] mm: disallow ioremaping ordinary RAM in generic_access_phys() Date: Sat, 7 Nov 2026 08:57:06 -0500 Message-ID: <20261107134918.022281016@linuxfoundation.org> X-Mailer: git-send-email 2.56.0 In-Reply-To: <20261107134852.069646174@linuxfoundation.org> References: <20261107134852.069646174@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: stable@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.18-stable review patch. If anyone has any objections, please let me know. ------------------ From: David Hildenbrand (Arm) [ Upstream commit 4590752e20aa393cc0d4fe538c0747d14a98c97a ] generic_access_phys() can end up getting called on CoW PFNMAP mappings, resulting in it trying to ioremap anonymous folios, which especially the x86 code doesn't enjoy, and which is in general just odd/wrong. E.g., with a CoW mapping of a PCI BAR: ioremap on RAM at 0x0000000045623000 - 0x0000000045623fff WARNING: arch/x86/mm/ioremap.c:216 at __ioremap_caller.isra.0+0x4c2/0x5f0 Call Trace: generic_access_phys+0x130/0x4d0 mm/memory.c:7178 kernfs_vma_access+0x1ce/0x280 fs/kernfs/file.c:437 __access_remote_vm+0x58f/0x890 mm/memory.c:7256 mem_rw+0x2a1/0x670 fs/proc/base.c:912 But more generically, we should disallow access to anything that looks like ordinary RAM in the system: including allocating memory (e.g., alloc_pages) and mapping them in a VM_PFNMAP. For pages with an online memmap, allow only pages marked as reserved (PageReserved). This also includes memblock allocations, however, distinguishing them from other MMIO is tricky, and nobody should really be mapping them in a PFNMAP (except someone abusing /dev/mem, which we do not care about). So only allow access if there is no online memmap, or if the pages are marked reserved. Reject other pages with -EINVAL. Note that, just like other pfn_to_online_page() users, we won't care about concurrent memory offlining; mapping memory that can concurrently get offlined is highly dubious. Link: https://lore.kernel.org/20261013-generic_access_phys-v1-1-b3963ef76e37@kernel.org Fixes: 28b2ee20c7cb ("access_process_vm device memory infrastructure") Signed-off-by: David Hildenbrand (Arm) Signed-off-by: Andrew Morton Reported-by: Closes: https://syzkaller.appspot.com/bug?extid=49b1021becba70c1f3f6 Reported-by: Nguyen Ngoc Thang Closes: https://lore.kernel.org/r/20261001152524.171115-1-ngocthang2710.1999@gmail.com/ Reviewed-by: Lorenzo Stoakes (ARM) Acked-by: Mike Rapoport (Microsoft) Tested-by: Lance Yang Cc: Liam R. Howlett Cc: Vlastimil Babka Cc: Suren Baghdasaryan Cc: Michal Hocko Cc: Benjamin Herrenschmidt Cc: Peter Zijlstra Cc: Rik van Riel Cc: Signed-off-by: Sasha Levin --- mm/memory.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/mm/memory.c b/mm/memory.c index d755b5c1f1287..01d14ca0e74d2 100644 --- a/mm/memory.c +++ b/mm/memory.c @@ -6808,6 +6808,7 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, resource_size_t phys_addr; pgprot_t prot = __pgprot(0); void __iomem *maddr; + struct page *page; int offset = offset_in_page(addr); int ret = -EINVAL; bool writable; @@ -6822,6 +6823,19 @@ int generic_access_phys(struct vm_area_struct *vma, unsigned long addr, retry: if (follow_pfnmap_start(&args)) return -EINVAL; + + /* + * Reject anything that looks like ordinary RAM, including anonymous + * folios in CoW mappings or allocated kernel memory. Note that we + * cannot distinguish memblock allocations from non-RAM reliably, so + * we cannot easily reject them here. + */ + page = pfn_to_online_page(args.pfn); + if (page && !PageReserved(page)) { + follow_pfnmap_end(&args); + return -EINVAL; + } + prot = args.pgprot; phys_addr = (resource_size_t)args.pfn << PAGE_SHIFT; writable = args.writable; -- 2.53.0