Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=195.135.223.131 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796040015; b=jqDLplqJY8mQ+QYZBzJYEf6qJPY2PeCVumb6DGLWQGPv4M9AhUNBE8RTsPw9YBsbNt9g JO+60oDaCeEPGZRygrtCnZ8Zt3QD+oecLcC9elxNhN19el4BHf3XcAE88ar/C2n/E/gul uzzinKVTvr914UvkHLiyvL7SBTi4adx2UkbiPYT6Vpn3JPwOz8xaVU0ZKXMbxaKbbcp8S zFkBggMzgS5++vKVMNqs12bP+p8IMtuMlMvPTthQrivgtDCOjfBV3yxbkuZY90uW6j6Uc rrswpZc9I6OL7BfIIXO/LWylMtoz4wq5HsrMpURVN9Vo3Lq9VFbN+3c/vAo9B7H/eOg== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796040015; h=DMARC-Filter:Received:DKIM-Signature:DKIM-Signature:Received: Received:From:To:Cc:Subject:Date:Message-ID:X-Mailer:MIME-Version: Content-Transfer-Encoding:X-Spamd-Result:X-Spam-Score:X-Spam-Level: X-Spam-Flag; bh=zks1Ck3U+NQc3h67Pra+FhZqsEPHKnUalDxNQrWogCw=; b=wqaj59yZuuBqSXeR9Ap4IkBNE+AbdFuo1985uL4MXTT+2QTJFe2U/8SNR70H3ybtAWAn DiKnMbBW+uZZhFHiChVIUb68vKknR7J/w4LJbCsRqCwLwrlWSTGK9tlo88MCUdYBrfT74 vLS97iC5SsYCNR+HQ7HlOMeExl2uNBBc9QK3qwBUAY3eGaH3+i5sGKS2By0AzPViRrd/J +DJ35vP4KqYV9PN9pZbNR5pZkcxMORQsptDsqhvCSX7hxo+K8m9mt7nHuvvX3+F5dvB7I ZbcsaXaQopRvwJyUfr+tmyXWGwWzNYTSCQxJJUP71T1NeViKNFyVnPITwekboiCw51A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass header.from=suse.com; spf=pass smtp.mailfrom=suse.com; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=opfXYp1n; dkim=pass header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=Izv67L3A; arc=none smtp.remote-ip=195.135.223.131 Received: from smtp-out2.suse.de (smtp-out2.suse.de [195.135.223.131]) (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 205BE606A331 for ; Mon, 30 Nov 2026 12:00:13 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 205BE606A331 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=suse.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=suse.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=opfXYp1n; dkim=pass (1024-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=susede1 header.b=Izv67L3A Received: from imap1.dmz-prg2.suse.org (unknown [10.150.64.97]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by smtp-out2.suse.de (Postfix) with ESMTPS id EEEB81F458; Mon, 30 Nov 2026 12:00:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1796040012; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zks1Ck3U+NQc3h67Pra+FhZqsEPHKnUalDxNQrWogCw=; b=opfXYp1nAjSmdA31AVH7oo+PDTUettWPELCe16aE6Hi0G6yyFFdC5AHGH70o8VM+QjJmyM fJmNfdWXNA9flLxsH6fTKa/3lTGoMGHQPBAheLdgkh868Lz4iv7dayTX+h6AxewXwve7td LqZbzz1a40L+uc67xi49nVF08kBjZW8= Authentication-Results: smtp-out2.suse.de; none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=susede1; t=1796040010; h=from:from:reply-to:date:date:message-id:message-id:to:to:cc:cc: mime-version:mime-version: content-transfer-encoding:content-transfer-encoding; bh=zks1Ck3U+NQc3h67Pra+FhZqsEPHKnUalDxNQrWogCw=; b=Izv67L3ALEPP1ewyGBp3vVOuWAtSjaPxOUU943+mt6p+P5L5UIbcHlkAJRp4WayxP+kDcS Q900aKl6eXo6+06sahsygZxlnq/uIhOobigfR8CcaMLwAo4HrcRo8pwMZGGcIrngUG6KL+ nTV8f+hEMTGfwsFljKyIaIw3nnwqOzE= Received: from imap1.dmz-prg2.suse.org (localhost [127.0.0.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by imap1.dmz-prg2.suse.org (Postfix) with ESMTPS id 4EC7D13408; Mon, 30 Nov 2026 12:00:09 +0000 (UTC) Received: from dovecot-director2.suse.de ([2a07:de40:b281:106:10:150:64:167]) by imap1.dmz-prg2.suse.org with ESMTPSA id +4u7AEllDWv+cwAAD6G6ig (envelope-from ); Mon, 30 Nov 2026 12:00:09 +0000 From: Nikolay Borisov To: x86@kernel.org Cc: naveen@kernel.org, Dan Williams , Kees Cook , Ingo Molnar , Vishal Annapurve , Arnd Bergmann , Greg Kroah-Hartman , Michael Ellerman , Suzuki K Poulose , Nikolay Borisov , stable@vger.kernel.org Subject: [PATCH v3] x86/devmem: Drop /dev/mem access for confidential guests Date: Mon, 30 Nov 2026 14:00:02 +0200 Message-ID: <20261130120003.136771-1-nik.borisov@suse.com> X-Mailer: git-send-email 2.56.0 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 X-Spamd-Result: default: False [-11.80 / 50.00]; SUSE_INTERNAL_BYPASS(-9.00)[]; BAYES_HAM(-3.00)[100.00%]; MID_CONTAINS_FROM(1.00)[]; NEURAL_HAM_LONG(-1.00)[-1.000]; R_MISSING_CHARSET(0.50)[]; NEURAL_HAM_SHORT(-0.20)[-0.998]; MIME_GOOD(-0.10)[text/plain]; DBL_BLOCKED_OPENRESOLVER(0.00)[arndb.de:email,suse.com:email,arm.com:email,ellerman.id.au:email,linuxfoundation.org:email,intel.com:email,imap1.dmz-prg2.suse.org:helo]; FROM_HAS_DN(0.00)[]; ARC_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; RCPT_COUNT_TWELVE(0.00)[12]; TO_MATCH_ENVRCPT_ALL(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; RCVD_COUNT_TWO(0.00)[2]; FROM_EQ_ENVFROM(0.00)[]; DKIM_SIGNED(0.00)[suse.com:s=susede1]; TO_DN_SOME(0.00)[]; RCVD_TLS_ALL(0.00)[] X-Spam-Score: -11.80 X-Spam-Level: X-Spam-Flag: NO 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 --- Changes in V3: * Only select STRICT_DEVMEM if DEVMEM is also selected (Sashiko, Naveen) * Remove superfluous check for CONFIG_STRICT_DEVMEM, devmem_is_allowed is only called when it's enabled * Slightly modify the last 2 paragraphs of the changelog to reflect that this no longer follows the LOCKDOWN model and simply revokes memory access. And explicilty call out the omission of IO_STRICT_DEVMEM * Removed tags as the patch is sufficiently different now. arch/x86/Kconfig | 2 ++ arch/x86/mm/init.c | 9 +++++++++ 2 files changed, 11 insertions(+) diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig index 3159852fd6b3..52daab4758cf 100644 --- a/arch/x86/Kconfig +++ b/arch/x86/Kconfig @@ -901,6 +901,7 @@ config INTEL_TDX_GUEST depends on X86_X2APIC depends on EFI_STUB depends on PARAVIRT + select STRICT_DEVMEM if DEVMEM select ARCH_HAS_CC_PLATFORM select X86_MEM_ENCRYPT select X86_MCE @@ -1490,6 +1491,7 @@ config AMD_MEM_ENCRYPT bool "AMD Secure Memory Encryption (SME) support" depends on X86_64 && CPU_SUP_AMD depends on EFI_STUB + select STRICT_DEVMEM if DEVMEM select DMA_COHERENT_POOL select ARCH_USE_MEMREMAP_PROT select INSTRUCTION_DECODER diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c index 079f8c7e9e3c..b4ff015cd770 100644 --- a/arch/x86/mm/init.c +++ b/arch/x86/mm/init.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include @@ -866,6 +867,14 @@ void __init poking_init(void) */ int devmem_is_allowed(unsigned long pagenr) { + /* + * Enforce encrypted mapping consistency and avoid unaccepted + * memory conflicts, "lockdown" /dev/mem for confidential + * guests. + */ + if (cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT)) + return 0; + if (region_intersects(PFN_PHYS(pagenr), PAGE_SIZE, IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) != REGION_DISJOINT) { -- 2.56.0