From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=209.85.221.46 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796368769; b=Pt5cQmSzi8ZutijuRdL8sRzFkhhN5uiiBWXLh7bET1omwc+HDeNhvtGPYI+k6cU6JXPm HlrZb0cWwRO2MAs9GjSlA/m6HW9EpnueVteSTOO9mvYNL5OicOgSILaxkuybDQF15k8eR /DdffHis6nAihwyrsZQ4hr+3dJnziRn1mfUdnPyiNxa4od8tJRqjBB9FKx5GQDLColgG4 ShgEhZ2+49zLy13cXXkxlknchj1gQJjcDbFQ2RTV4hdf7cdduj9AQzc7OFyG3UkJarxMK CslMT/4SNrYX5IN1Z/ei7x1zqFLaE8euMS+GB6ZEJsDsDVPkPugXI2cJdXUsoiLcs0A== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796368769; h=DMARC-Filter:Received:DKIM-Signature:X-Google-DKIM-Signature: X-Forwarded-Encrypted:X-Gm-Message-State:X-Gm-Gg:X-Received:Received: Message-ID:Date:MIME-Version:User-Agent:Subject:To:Cc:References:From: Content-Language:Autocrypt:In-Reply-To:Content-Type: Content-Transfer-Encoding; bh=bV8i1q3OFS1dkkEX7yhadw9b1Qun2MYsGLODV4s0xMc=; b=uAvwwISpYmwAAY2TRcm8ukyrc2TK6lDZAdGFXuk0yAalJD9VDYGv8fl3HDtAlw+1qKCG atTcW42EW9hBZeF1tmIsUPoXPyWwtR45tdIHJjroAlVx7AMDjFDFTXCOZEy8muCTxjEDR Drcc1vksQVcjUnMakfYnfgHaw3idnXxiQlwbtSjXXr9c7STR3a+kbVRJkheEuHWfit1bE h+uIOCOiffqFwC50901XmP4PsTbU3QnGojkfxfTSWBCW42oQMnGqVaGdBaXViETgTsQXd xVFp83bBJE/P6IcR8mQgGfaK5Z7leuSoczF4wNiyOAcMinEejsPc+X8UrfVJWgWJbag== 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=google header.b=NkGhNRUs; arc=none smtp.remote-ip=209.85.221.46 Received: from mail-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EE0A8606A322 for ; Fri, 4 Dec 2026 07:19:28 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org EE0A8606A322 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 (2048-bit key) header.d=suse.com header.i=@suse.com header.a=rsa-sha256 header.s=google header.b=NkGhNRUs Received: by mail-wr1-f46.google.com with SMTP id ffacd0b85a97d-49412eb1474so183291f8f.3 for ; Thu, 03 Dec 2026 23:19:28 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=suse.com; s=google; t=1796368767; x=1796973567; darn=vger.kernel.org; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:from:to:cc:subject:date:message-id :reply-to:content-type; bh=bV8i1q3OFS1dkkEX7yhadw9b1Qun2MYsGLODV4s0xMc=; b=NkGhNRUsltaJpaYxOBOqproTeKwR+ND1FKL4B7Zmo7BIJCRdJPNMVVLT8E0lXzjJy/ ly4Z0yrRPfg1sgKQ+HZblJcOb/1ebLVrku5X7pRZgenGVqdRaybMJKy8ioUfckCMq3EP Y/oE9i97tbmfM7OgFYC/LSuJ6hSaZ0YjC6HVaRmWN1mVrUzy+7fq4SgnHchmNSTMfH1R 2CQivWzo75aijYGZRYccheOEw1Jq8e4WDx5CFx8jAUo3TY5DAh1NFewCrcKXD/dlSobL +a/eSMFEf+MgEL650xmjyjA81mjMURs7qXd7PrS3viSbfnwGyo5vNa/+qDt7Dofmqwr9 ApKg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20260707; t=1796368767; x=1796973567; h=content-transfer-encoding:content-type:in-reply-to:autocrypt :content-language:from:references:cc:to:subject:user-agent :mime-version:date:message-id:x-gm-gg:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to:content-type; bh=bV8i1q3OFS1dkkEX7yhadw9b1Qun2MYsGLODV4s0xMc=; b=melRCwBhczDPgHOXQaERGSLNd/JIMg+JgGfj482Cy5VE2FUEzBf1XIiSEqBhZWHxJ/ uWCof2o/t7xjg2H23wwJvzAyRu36tWpv1/HJ0L+juO5+eLQOikuT7yakkVPeYLk8rfKo pW3JyV0oF6FPit9aS9toSoIZvts2p6FYNWaxcglMx1X93TfmD8VS3D1NZwvZ1tz2IHNa I1sCSxE4ahIM/5h7gPeuQ+4+iciE6OxpREw8EWjPMhhnkoK0pg1b2JrMrKLOxPM/gf8j 7eDL9ws29COMLJlCYMWLMnhQKNyzVt1mxGG0A0S+EgTGkFB0XijHk10S36KBkQn8+sjC wgWA== X-Forwarded-Encrypted: i=1; AL+hErH7Yp34Ro6rjecPbBjytD3iUYBKLDMxnss9oDocFRxWG4lvrgE3W5cOhapi/xY77hTDyMS9m4w=@vger.kernel.org X-Gm-Message-State: APuU4Z/4n1LQ6Ybci1pO+BX4KbdsQrLKUFCKhnl8rMOlYcEdqJ4p5W1G DT7RdHsX9H8k7EBalKnTgEEOeJDtxd4ei4S7vHx7XuSanvvPaNX+2E3G/qhM8W6+19E= X-Gm-Gg: AZFdTZeCWUQTUbG3sgGlcII5gyALjbtA7mQTjx4pv5zr3KcTQ4GnQ8JRC/VwVZc2Th5 DKO+pvdMUg7KkTL1v7U2BzkZV5rttLZgP9wP6JSTv7Gq2CeG/+OGxvS2X/DybUkKKNgugaaYPBa trPdgpB8tySgEBisJ3QeLBWGD+jqy7GcuyG9eCJpYLR6wrQ6ylgQFwU1H+LyKWFskX02DAve6cw uOXzQwwUMwQs7XhRHBuYFNHcnhaTMCcxPnxCZ1GyqJhhlnv9Cher8Pe4Tw76g7PFFkCK3X07be+ OCfj0RjLn3p9tOy5KdGfQwtmi8MEs/a0xsfoXGd5wAEWwA1Nm+MJjEHsS+A4nxbguBqjZcY25c0 /y0BmI7wRMDi3++wZVxtl0crCfpXdvejTQuIL2HbB5iRIYP0nSF+Zw6uFfMvV4ZFQGRWYJHpP0U aSXgLqP8HhvxcBDe/+Vlsqs54VSFCcOWSulj4gcs7S5l0X573yJ0F+OjIDh8By0+6Jju+rQ+5hM wBX1QtPEU3TQY+si0hdZ+MY3Dj4ph3GWmBYyu9QmQmFCrMDQVkHzv7Q0q54QFPaIMYziSxctYlB WPz2n0vneVtL9XFbkqWYQHCoOZtzARPpBizXCLwT+CvV5OvLIrFJ X-Received: by 2002:a05:6000:29da:b0:492:20e0:f200 with SMTP id ffacd0b85a97d-4d1e8dbcf92mr1361743f8f.14.1796368767265; Thu, 03 Dec 2026 23:19:27 -0800 (PST) Received: from [192.168.0.20] (nborisov.ddns.nbis.net. [85.187.216.251]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-4d172e41e27sm3292644f8f.21.2026.12.03.23.19.26 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2026 23:19:26 -0800 (PST) Message-ID: <91d98178-3ef3-42c6-aab2-e85a70655722@suse.com> Date: Fri, 4 Dec 2026 09:19:25 +0200 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 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v3] x86/devmem: Drop /dev/mem access for confidential guests To: "Edgecombe, Rick P" , "x86@kernel.org" Cc: "kees@kernel.org" , "mingo@kernel.org" , "gregkh@linuxfoundation.org" , "Annapurve, Vishal" , "suzuki.poulose@arm.com" , "naveen@kernel.org" , "arnd@arndb.de" , "mpe@ellerman.id.au" , "stable@vger.kernel.org" References: <20261130120003.136771-1-nik.borisov@suse.com> <72e1cc61ffc87dbae62a56681803af0b6c1ccc4a.camel@intel.com> From: Nikolay Borisov Content-Language: en-US Autocrypt: addr=nik.borisov@suse.com; keydata= xsFNBGcrpvIBEAD5cAR5+qu30GnmPrK9veWX5RVzzbgtkk9C/EESHy9Yz0+HWgCVRoNyRQsZ 7DW7vE1KhioDLXjDmeu8/0A8u5nFMqv6d1Gt1lb7XzSAYw7uSWXLPEjFBtz9+fBJJLgbYU7G OpTKy6gRr6GaItZze+r04PGWjeyVUuHZuncTO7B2huxcwIk9tFtRX21gVSOOC96HcxSVVA7X N/LLM2EOL7kg4/yDWEhAdLQDChswhmdpHkp5g6ytj9TM8bNlq9I41hl/3cBEeAkxtb/eS5YR 88LBb/2FkcGnhxkGJPNB+4Siku7K8Mk2Y6elnkOctJcDvk29DajYbQnnW4nhfelZuLNupb1O M0912EvzOVI0dIVgR+xtosp66bYTOpX4Xb0fylED9kYGiuEAeoQZaDQ2eICDcHPiaLzh+6cc pkVTB0sXkWHUsPamtPum6/PgWLE9vGI5s+FaqBaqBYDKyvtJfLK4BdZng0Uc3ijycPs3bpbQ bOnK9LD8TYmYaeTenoNILQ7Ut54CCEXkP446skUMKrEo/HabvkykyWqWiIE/UlAYAx9+Ckho TT1d2QsmsAiYYWwjU8igXBecIbC0uRtF/cTfelNGrQwbICUT6kJjcOTpQDaVyIgRSlUMrlNZ XPVEQ6Zq3/aENA8ObhFxE5PLJPizJH6SC89BMKF3zg6SKx0qzQARAQABzSZOaWtvbGF5IEJv cmlzb3YgPG5pay5ib3Jpc292QHN1c2UuY29tPsLBkQQTAQoAOxYhBDuWB8EJLBUZCPjT3SRn XZEnyhf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yM2L6E604NbDu0VDvHg7EXh1WwmijEu28c/hEB6DwtzslLpBSsJV0s1/jE= In-Reply-To: <72e1cc61ffc87dbae62a56681803af0b6c1ccc4a.camel@intel.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit On 4.12.26 г. 1:08 ч., Edgecombe, Rick P wrote: > On Mon, 2026-11-30 at 14:00 +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. > > Long line^ > >> 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. > > At a high level the history of /dev/mem, is that various issues were found. To > prevent breaking userspace they were fixed behind optional Kconfig options, > which became kind of the default config over time. Right? Now another issue was > found with the BIOS range and mmap(). The proposal here is to remove the > /dev/mem altogether for coco VMs, in a potentially backward incompatible way > (offline Nikolay suggested this is not likely. I can see it). But this makes > coco special mandated behavior, removes possibly working cases, and doesn't fix > the issue for non-coco VMs. > > Why not fix the mmap issue in the same way as the other /dev/mem lockdowns? I'd like to refrain from adding more and more knobs. > >> >> 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. > > Hmm. Might be racy though? Why would it be racy? > >> >> 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 > > I think there are various recommendations to do this already for TDX guests. > There are quite a bit of lockdowns suggested for TDX guests that we don't > enforce in the kernel source. So why treat this one special? > >> 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; > > This includes SEV and SEV-ES which I'd think would not have the problem? Or at > least the same symptoms. On the contrary, SEV also experiences problems. > >> + >> if (region_intersects(PFN_PHYS(pagenr), PAGE_SIZE, >> IORESOURCE_SYSTEM_RAM, IORES_DESC_NONE) >> != REGION_DISJOINT) { >> -- >> 2.56.0 >> >