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=1796048052; b=G3HyAdcJaUaTz2qW1TdXbbXdHFupEqQPLdPT1PVFF51ZgAtQqbTarKQvXTSIzvJK5gLu lZ4FRLoeFIfvA6kWRQwBTdHPYhnffm/cwDD2KVUs6q5Yl2EPmgkF9/dHhJZgC3dGygXFU JTT7WjuGUitSt/VIdQ7GyGHf6qz4Y1xihlCasFFPPHgc9sn2efGpdn+L4HIEMXUStvzR3 KfkHzcBQDrTGpFBYMQhsSCshSST8ElO39Txh4ZH/4GvqSOVq+HXp4+LodiTnxVdmQbIMM gREUZU8aaStmTaKwXII/6pASeA9WxVcaa8ErDXnrq3VrEr8AKxMI1wIdRDq8bYCktPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796048052; h=Received:DKIM-Signature:Date:From:To:Cc:Subject:Message-ID: References:MIME-Version:Content-Type:Content-Disposition:In-Reply-To; bh=SFJIIgkxlteKWAa3r2Vmnuxr4Pig6gFk3U6JAy6ckOI=; b=hhgNC14Hv1WDYiuOfy4/SyUvs6VXcOZ0rr3aeLXoDB8ZT443/9xC/OYDpnexJq6+9ZRf NlZeyjVMHONCyTz3pBmsHV4d6hl54gS/VFpzYD0uG1UbC41ilYiSiz/88jiDJE2xXiF3Q qufCiZCdtC5R8Jjo8sRfU13BFLIIFtkdsAnS2ZjKeoyxD3sQH11J6cK+Zg851Z8o8qY69 Q/RPdJtBtMGaoAhUQ2Kk4cJ92lojtdnGCRLkQhS4+R8TQtbmQzMMacUzpomte4+x/pyyn FI6SG38SlvMtwywb/PBJ4gvXLswChGYjDeqfLRD5UsaAf6I89dmla1nzIsnu56+PSvA== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XcH6Scc1; 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 EC869606A320 for ; Mon, 30 Nov 2026 14:14:11 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=XcH6Scc1 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80DC71F00896; Mon, 30 Nov 2026 14:14:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796048051; bh=SFJIIgkxlteKWAa3r2Vmnuxr4Pig6gFk3U6JAy6ckOI=; h=Date:From:To:Cc:Subject:References:In-Reply-To; b=XcH6Scc1rPwbwl28CKlVkazEboWGgkGBr/ZOFUGxql8jhiBvNWi/BbrV3pYgo2/CW B5zQdW3EclhMCXPMGG6qaIDKGVNWH+XUeb18/26EJY2adV6HyBdpLg+WojhFEIpgpL Y9yQ9kZRzYY4fVxP2E8BJsQRCuMh9/jMIM+UpTMMrrzLj63f9kjtDey3fDMJO42P7/ UZvLXLPZP0fln1ZnwfasUE9uA0hY9GNpBHPA/nE0Eb77Ws6+ZtpFcPanO3o2tKhl0+ qnz6wWj+np80EPAr750CPYALNDSlUbr404whN0u6DyM3Zgdyj52yDwd1hfNVM5BLOB 39eNLDu7emXlA== Date: Mon, 30 Nov 2026 19:33:41 +0530 From: Naveen N Rao To: Nikolay Borisov Cc: x86@kernel.org, Dan Williams , Kees Cook , Ingo Molnar , Vishal Annapurve , Arnd Bergmann , Greg Kroah-Hartman , Michael Ellerman , Suzuki K Poulose , stable@vger.kernel.org Subject: Re: [PATCH v3] x86/devmem: Drop /dev/mem access for confidential guests Message-ID: References: <20261130120003.136771-1-nik.borisov@suse.com> 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-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261130120003.136771-1-nik.borisov@suse.com> On Mon, Nov 30, 2026 at 02:00:02PM +0200, Nikolay Borisov wrote: > From: Dan Williams > > Nikolay reports that accessing BIOS data (first 1MB of the physical > address space) via /dev/mem results in a "crash" / terminated VM > (unhandled SEPT violation). See report [1] for details. > > The cause is ioremap() (via xlate_dev_mem_ptr()) establishes an > unencrypted mapping where the kernel had established an encrypted > mapping previously. The CPU enforces mapping consistency with a fault > upon detecting a mismatch. A similar situation arises with devmem access > to "unaccepted" confidential memory. In summary, it is fraught to allow > uncoordinated userspace mapping of confidential memory. > > While there is an existing mitigation to simulate and redirect access to > the BIOS data area with STRICT_DEVMEM=y, it is insufficient. > Specifically, STRICT_DEVMEM=y traps read(2) access to the BIOS data > area, and returns a zeroed buffer. However, it turns out the kernel > fails to enforce the same via mmap(2), and a direct mapping is > established. This is a hole, and unfortunately userspace has learned to > exploit it [2]. > > This means the kernel either needs: a mechanism to ensure consistent > plus accepted "encrypted" mappings of this /dev/mem mmap() hole, close > the hole by mapping the zero page in the mmap(2) path, block only BIOS > data access and let typical STRICT_DEVMEM protect the rest, or disable > /dev/mem altogether. > > The simplest option for now is to revoke memory access via /dev/mem for confidential guests. > Require confidential guest userspace to jettison legacy dependencies on > /dev/mem similar to how other legacy mechanisms are jettisoned for > confidential operation. Recall that modern methods for BIOS data > access are available like /sys/firmware/dmi/tables. > > Now, this begs the question what to do with PCI sysfs which allows > userspace mappings of confidential MMIO with similar mapping consistency > and acceptance expectations? Here, the existing mitigation of > IO_STRICT_DEVMEM is likely sufficient. The kernel is expected to use > request_mem_region() when toggling the state of MMIO. With > IO_STRICT_DEVMEM that enforces kernel-exclusive access until > release_mem_region(), i.e. mapping conflicts are prevented. However, > this is left out for relevant series when secure MMIO support starts > landing. > > Cc: x86@kernel.org > Cc: Kees Cook > Cc: Ingo Molnar > Cc: Vishal Annapurve > Cc: Arnd Bergmann > Cc: Greg Kroah-Hartman > Cc: Michael Ellerman > Cc: Suzuki K Poulose > Link: https://sources.debian.org/src/libdebian-installer/0.125/src/system/subarch-x86-linux.c/?hl=113#L93 [2] > Reported-by: Nikolay Borisov > Closes: http://lore.kernel.org/20250318113604.297726-1-nik.borisov@suse.com [1] > Fixes: 9aa6ea69852c ("x86/tdx: Make pages shared in ioremap()") > Cc: stable@vger.kernel.org > Signed-off-by: Dan Williams > Signed-off-by: Nikolay Borisov > --- Also: Fixes: 81256a50aa0f ("x86/mm: Make memremap(MEMREMAP_WB) map memory as encrypted by default") ... since SEV-SNP guests now terminate on read() of a non-RAM page in the first 1 MB area (e.g., video ROM at 0xc0000). Other than that, I have tested this patch and it prevents #VC due to mmap()/read() issued on /dev/mem fd. Acked-by: Naveen N Rao (AMD) Tested-by: Naveen N Rao (AMD) Thanks, Naveen