* [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
@ 2026-11-24 16:00 Nikolay Borisov
2026-11-24 16:29 ` Arnd Bergmann
` (3 more replies)
0 siblings, 4 replies; 12+ messages in thread
From: Nikolay Borisov @ 2026-11-24 16:00 UTC (permalink / raw)
To: x86
Cc: mhocko, kas, ljs, linux-mm, linux-kernel, Dan Williams, Kees Cook,
Ingo Molnar, Vishal Annapurve, Kirill Shutemov, Arnd Bergmann,
Greg Kroah-Hartman, Michael Ellerman, Suzuki K Poulose,
Nikolay Borisov, Dave Hansen, Naveen N Rao (AMD)
From: Dan Williams <dan.j.williams@intel.com>
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 arrange for /dev/mem to always behave as
if lockdown is enabled 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.
Cc: x86@kernel.org
Cc: Kees Cook <kees@kernel.org>
Cc: Ingo Molnar <mingo@kernel.org>
Cc: Vishal Annapurve <vannapurve@google.com>
Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: Michael Ellerman <mpe@ellerman.id.au>
Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
Link: https://sources.debian.org/src/libdebian-installer/0.125/src/system/subarch-x86-linux.c/?hl=113#L93 [2]
Reported-by: Nikolay Borisov <nik.borisov@suse.com>
Closes: http://lore.kernel.org/20250318113604.297726-1-nik.borisov@suse.com [1]
Fixes: 9aa6ea69852c ("x86/tdx: Make pages shared in ioremap()")
Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
Acked-by: Naveen N Rao (AMD) <naveen@kernel.org>
Tested-by: Naveen N Rao (AMD) <naveen@kernel.org>
Signed-off-by: Dan Williams <dan.j.williams@intel.com>
Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
---
Resending this with the hope of either getting it accepted or arriving at a consensus
what exactly is missing so that I can take it from there and eventually get something
merged. As previously mentioned this results in real problems for confidential
guests both on TDX as well as SEV-SNP.
arch/x86/Kconfig | 4 ++++
mm/char-mem.c | 10 ++++++++++
2 files changed, 14 insertions(+)
diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
index 3159852fd6b3..1490e0019c71 100644
--- a/arch/x86/Kconfig
+++ b/arch/x86/Kconfig
@@ -901,6 +901,8 @@ config INTEL_TDX_GUEST
depends on X86_X2APIC
depends on EFI_STUB
depends on PARAVIRT
+ select STRICT_DEVMEM
+ select IO_STRICT_DEVMEM
select ARCH_HAS_CC_PLATFORM
select X86_MEM_ENCRYPT
select X86_MCE
@@ -1490,6 +1492,8 @@ 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
+ select IO_STRICT_DEVMEM
select DMA_COHERENT_POOL
select ARCH_USE_MEMREMAP_PROT
select INSTRUCTION_DECODER
diff --git a/mm/char-mem.c b/mm/char-mem.c
index c5761ddedbd7..5d383befd87d 100644
--- a/mm/char-mem.c
+++ b/mm/char-mem.c
@@ -30,6 +30,7 @@
#include <linux/uio.h>
#include <linux/uaccess.h>
#include <linux/security.h>
+#include <linux/cc_platform.h>
#include "internal.h"
@@ -609,6 +610,15 @@ static int open_port(struct inode *inode, struct file *filp)
if (rc)
return rc;
+ /*
+ * Enforce encrypted mapping consistency and avoid unaccepted
+ * memory conflicts, "lockdown" /dev/mem for confidential
+ * guests.
+ */
+ if (IS_ENABLED(CONFIG_STRICT_DEVMEM) &&
+ cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
+ return -EPERM;
+
if (iminor(inode) != DEVMEM_MINOR)
return 0;
--
2.56.0
^ permalink raw reply related [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 16:00 [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests Nikolay Borisov
@ 2026-11-24 16:29 ` Arnd Bergmann
2026-11-24 16:36 ` Dave Hansen
` (2 subsequent siblings)
3 siblings, 0 replies; 12+ messages in thread
From: Arnd Bergmann @ 2026-11-24 16:29 UTC (permalink / raw)
To: Nikolay Borisov, x86
Cc: Michal Hocko, Kirill A. Shutemov, Lorenzo Stoakes, linux-mm,
linux-kernel, Dan Williams, Kees Cook, Ingo Molnar,
Vishal Annapurve, Kirill A. Shutemov, Greg Kroah-Hartman,
Michael Ellerman, Suzuki K Poulose, Dave Hansen, Naveen N Rao
On Tue, Nov 24, 2026, at 17:00, Nikolay Borisov wrote:
> From: Dan Williams <dan.j.williams@intel.com>
>
> Resending this with the hope of either getting it accepted or arriving
> at a consensus
> what exactly is missing so that I can take it from there and eventually
> get something
> merged. As previously mentioned this results in real problems for
> confidential
> guests both on TDX as well as SEV-SNP.
I do think we should go further than this, but the patch solves
a real problem and it doesn't stop us from doing more later, so
Acked-by: Arnd Bergmann <arnd@arndb.de>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 16:00 [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests Nikolay Borisov
2026-11-24 16:29 ` Arnd Bergmann
@ 2026-11-24 16:36 ` Dave Hansen
2026-11-24 17:10 ` Pedro Falcato
2026-11-25 16:01 ` sashiko-bot
2026-11-26 8:28 ` Nikolay Borisov
3 siblings, 1 reply; 12+ messages in thread
From: Dave Hansen @ 2026-11-24 16:36 UTC (permalink / raw)
To: Nikolay Borisov, x86
Cc: mhocko, kas, ljs, linux-mm, linux-kernel, Dan Williams, Kees Cook,
Ingo Molnar, Vishal Annapurve, Kirill Shutemov, Arnd Bergmann,
Greg Kroah-Hartman, Michael Ellerman, Suzuki K Poulose,
Dave Hansen, Naveen N Rao (AMD), Liam R. Howlett, Andrew Morton,
Lorenzo Stoakes, Vlastimil Babka, Pedro Falcato,
David Hildenbrand
On 11/24/26 08:00, Nikolay Borisov wrote:
> Resending this with the hope of either getting it accepted or
> arriving at a consensus what exactly is missing so that I can take
> it from there and eventually get something merged. As previously
> mentioned this results in real problems for confidential guests both
> on TDX as well as SEV-SNP.>
> arch/x86/Kconfig | 4 ++++
> mm/char-mem.c | 10 ++++++++++
> 2 files changed, 14 insertions(+)
I'm still OK with doing this.
But I didn't want to sneak an mm/ change in via the tip tree. Any mm
acks or naks on this?
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 16:36 ` Dave Hansen
@ 2026-11-24 17:10 ` Pedro Falcato
2026-11-24 17:35 ` Greg Kroah-Hartman
2026-11-24 17:57 ` Nikolay Borisov
0 siblings, 2 replies; 12+ messages in thread
From: Pedro Falcato @ 2026-11-24 17:10 UTC (permalink / raw)
To: Dave Hansen
Cc: Nikolay Borisov, x86, mhocko, linux-mm, linux-kernel,
Dan Williams, Kees Cook, Ingo Molnar, Vishal Annapurve,
Kirill Shutemov, Arnd Bergmann, Greg Kroah-Hartman,
Michael Ellerman, Suzuki K Poulose, Dave Hansen,
Naveen N Rao (AMD), Liam R. Howlett, Andrew Morton,
Lorenzo Stoakes, Vlastimil Babka, David Hildenbrand
Holy cow the CC list is stale.
Fixing some up.
On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
> On 11/24/26 08:00, Nikolay Borisov wrote:
> > Resending this with the hope of either getting it accepted or
> > arriving at a consensus what exactly is missing so that I can take
> > it from there and eventually get something merged. As previously
> > mentioned this results in real problems for confidential guests both
> > on TDX as well as SEV-SNP.>
> > arch/x86/Kconfig | 4 ++++
> > mm/char-mem.c | 10 ++++++++++
> > 2 files changed, 14 insertions(+)
>
> I'm still OK with doing this.
>
> But I didn't want to sneak an mm/ change in via the tip tree. Any mm
> acks or naks on this?
For what it's worth, I don't love this fix. Yes, it fixes issues in /dev/mem,
but it:
1) skips any other potential problem spots (I don't know which)
2) open-codes random CC checks in mm, which is kind-of regrettable
OTOH, it's unclear to me why that CC check is needed. If configs select
STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
in iomem_is_exclusive, etc. If not, could the CC awareness sit there
instead?
/me doesn't know much about CC other than *if you touch something you shouldn't,
it goes boom*
--
Pedro
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 17:10 ` Pedro Falcato
@ 2026-11-24 17:35 ` Greg Kroah-Hartman
2026-11-24 17:53 ` Nikolay Borisov
2026-11-24 17:57 ` Nikolay Borisov
1 sibling, 1 reply; 12+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-24 17:35 UTC (permalink / raw)
To: Pedro Falcato
Cc: Dave Hansen, Nikolay Borisov, x86, mhocko, linux-mm, linux-kernel,
Dan Williams, Kees Cook, Ingo Molnar, Vishal Annapurve,
Kirill Shutemov, Arnd Bergmann, Michael Ellerman,
Suzuki K Poulose, Dave Hansen, Naveen N Rao (AMD),
Liam R. Howlett, Andrew Morton, Lorenzo Stoakes, Vlastimil Babka,
David Hildenbrand
On Tue, Nov 24, 2026 at 05:10:21PM +0000, Pedro Falcato wrote:
> Holy cow the CC list is stale.
> Fixing some up.
>
> On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
> > On 11/24/26 08:00, Nikolay Borisov wrote:
> > > Resending this with the hope of either getting it accepted or
> > > arriving at a consensus what exactly is missing so that I can take
> > > it from there and eventually get something merged. As previously
> > > mentioned this results in real problems for confidential guests both
> > > on TDX as well as SEV-SNP.>
> > > arch/x86/Kconfig | 4 ++++
> > > mm/char-mem.c | 10 ++++++++++
> > > 2 files changed, 14 insertions(+)
> >
> > I'm still OK with doing this.
> >
> > But I didn't want to sneak an mm/ change in via the tip tree. Any mm
> > acks or naks on this?
>
> For what it's worth, I don't love this fix. Yes, it fixes issues in /dev/mem,
> but it:
> 1) skips any other potential problem spots (I don't know which)
> 2) open-codes random CC checks in mm, which is kind-of regrettable
>
> OTOH, it's unclear to me why that CC check is needed. If configs select
> STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
> in iomem_is_exclusive, etc. If not, could the CC awareness sit there
> instead?
Yeah, why is anyone letting a CC system access /dev/mem at all? That's
ripe for abuse lots of different ways, so I really don't like this
change either.
thanks,
greg k-h
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 17:35 ` Greg Kroah-Hartman
@ 2026-11-24 17:53 ` Nikolay Borisov
2026-11-25 5:06 ` Greg Kroah-Hartman
0 siblings, 1 reply; 12+ messages in thread
From: Nikolay Borisov @ 2026-11-24 17:53 UTC (permalink / raw)
To: Greg Kroah-Hartman, Pedro Falcato
Cc: Dave Hansen, x86, mhocko, linux-mm, linux-kernel, Dan Williams,
Kees Cook, Ingo Molnar, Vishal Annapurve, Kirill Shutemov,
Arnd Bergmann, Michael Ellerman, Suzuki K Poulose, Dave Hansen,
Naveen N Rao (AMD), Liam R. Howlett, Andrew Morton,
Lorenzo Stoakes, Vlastimil Babka, David Hildenbrand
On 24.11.26 г. 19:35 ч., Greg Kroah-Hartman wrote:
> On Tue, Nov 24, 2026 at 05:10:21PM +0000, Pedro Falcato wrote:
>> Holy cow the CC list is stale.
>> Fixing some up.
>>
>> On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
>>> On 11/24/26 08:00, Nikolay Borisov wrote:
>>>> Resending this with the hope of either getting it accepted or
>>>> arriving at a consensus what exactly is missing so that I can take
>>>> it from there and eventually get something merged. As previously
>>>> mentioned this results in real problems for confidential guests both
>>>> on TDX as well as SEV-SNP.>
>>>> arch/x86/Kconfig | 4 ++++
>>>> mm/char-mem.c | 10 ++++++++++
>>>> 2 files changed, 14 insertions(+)
>>>
>>> I'm still OK with doing this.
>>>
>>> But I didn't want to sneak an mm/ change in via the tip tree. Any mm
>>> acks or naks on this?
>>
>> For what it's worth, I don't love this fix. Yes, it fixes issues in /dev/mem,
>> but it:
>> 1) skips any other potential problem spots (I don't know which)
>> 2) open-codes random CC checks in mm, which is kind-of regrettable
>>
>> OTOH, it's unclear to me why that CC check is needed. If configs select
>> STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
>> in iomem_is_exclusive, etc. If not, could the CC awareness sit there
>> instead?
>
> Yeah, why is anyone letting a CC system access /dev/mem at all? That's
> ripe for abuse lots of different ways, so I really don't like this
> change either.
You are missing the point, this pertains to /dev/mem in the guest. There
are a bunch of libraries (libhd for example) which reads the first meg
of memory. This causes the CC guest to shutdown in both AMD-SEVSNP and
TDX world.
>
> thanks,
>
> greg k-h
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 17:10 ` Pedro Falcato
2026-11-24 17:35 ` Greg Kroah-Hartman
@ 2026-11-24 17:57 ` Nikolay Borisov
2026-11-25 16:51 ` Naveen N Rao
1 sibling, 1 reply; 12+ messages in thread
From: Nikolay Borisov @ 2026-11-24 17:57 UTC (permalink / raw)
To: Pedro Falcato, Dave Hansen
Cc: x86, mhocko, linux-mm, linux-kernel, Kees Cook, Ingo Molnar,
Vishal Annapurve, Kirill Shutemov, Arnd Bergmann,
Greg Kroah-Hartman, Michael Ellerman, Suzuki K Poulose,
Dave Hansen, Naveen N Rao (AMD), Liam R. Howlett, Andrew Morton,
Lorenzo Stoakes, Vlastimil Babka, David Hildenbrand
On 24.11.26 г. 19:10 ч., Pedro Falcato wrote:
> Holy cow the CC list is stale.
> Fixing some up.
>
> On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
>> On 11/24/26 08:00, Nikolay Borisov wrote:
>>> Resending this with the hope of either getting it accepted or
>>> arriving at a consensus what exactly is missing so that I can take
>>> it from there and eventually get something merged. As previously
>>> mentioned this results in real problems for confidential guests both
>>> on TDX as well as SEV-SNP.>
>>> arch/x86/Kconfig | 4 ++++
>>> mm/char-mem.c | 10 ++++++++++
>>> 2 files changed, 14 insertions(+)
>>
>> I'm still OK with doing this.
>>
>> But I didn't want to sneak an mm/ change in via the tip tree. Any mm
>> acks or naks on this?
>
> For what it's worth, I don't love this fix. Yes, it fixes issues in /dev/mem,
> but it:
> 1) skips any other potential problem spots (I don't know which)
Well that's not saying much. Of course there are thousands of bugs
lurking around the kernel and not any one patch fixes them all.
> 2) open-codes random CC checks in mm, which is kind-of regrettable
>
> OTOH, it's unclear to me why that CC check is needed. If configs select
> STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
> in iomem_is_exclusive, etc. If not, could the CC awareness sit there
> instead?
Well, you are right that if we retain just the select
STRICT_DEVMEM/IO_STRICT_DEVMEM it might fix the immediate issue. I don't
know why eventually Dan decided to also add this check, I guess it's an
instance of "fail fast".
>
> /me doesn't know much about CC other than *if you touch something you shouldn't,
> it goes boom*
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 17:53 ` Nikolay Borisov
@ 2026-11-25 5:06 ` Greg Kroah-Hartman
0 siblings, 0 replies; 12+ messages in thread
From: Greg Kroah-Hartman @ 2026-11-25 5:06 UTC (permalink / raw)
To: Nikolay Borisov
Cc: Pedro Falcato, Dave Hansen, x86, mhocko, linux-mm, linux-kernel,
Dan Williams, Kees Cook, Ingo Molnar, Vishal Annapurve,
Kirill Shutemov, Arnd Bergmann, Michael Ellerman,
Suzuki K Poulose, Dave Hansen, Naveen N Rao (AMD),
Liam R. Howlett, Andrew Morton, Lorenzo Stoakes, Vlastimil Babka,
David Hildenbrand
On Tue, Nov 24, 2026 at 07:53:53PM +0200, Nikolay Borisov wrote:
>
>
> On 24.11.26 г. 19:35 ч., Greg Kroah-Hartman wrote:
> > On Tue, Nov 24, 2026 at 05:10:21PM +0000, Pedro Falcato wrote:
> > > Holy cow the CC list is stale.
> > > Fixing some up.
> > >
> > > On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
> > > > On 11/24/26 08:00, Nikolay Borisov wrote:
> > > > > Resending this with the hope of either getting it accepted or
> > > > > arriving at a consensus what exactly is missing so that I can take
> > > > > it from there and eventually get something merged. As previously
> > > > > mentioned this results in real problems for confidential guests both
> > > > > on TDX as well as SEV-SNP.>
> > > > > arch/x86/Kconfig | 4 ++++
> > > > > mm/char-mem.c | 10 ++++++++++
> > > > > 2 files changed, 14 insertions(+)
> > > >
> > > > I'm still OK with doing this.
> > > >
> > > > But I didn't want to sneak an mm/ change in via the tip tree. Any mm
> > > > acks or naks on this?
> > >
> > > For what it's worth, I don't love this fix. Yes, it fixes issues in /dev/mem,
> > > but it:
> > > 1) skips any other potential problem spots (I don't know which)
> > > 2) open-codes random CC checks in mm, which is kind-of regrettable
> > >
> > > OTOH, it's unclear to me why that CC check is needed. If configs select
> > > STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
> > > in iomem_is_exclusive, etc. If not, could the CC awareness sit there
> > > instead?
> >
> > Yeah, why is anyone letting a CC system access /dev/mem at all? That's
> > ripe for abuse lots of different ways, so I really don't like this
> > change either.
>
> You are missing the point, this pertains to /dev/mem in the guest. There are
> a bunch of libraries (libhd for example) which reads the first meg of
> memory. This causes the CC guest to shutdown in both AMD-SEVSNP and TDX
> world.
Then don't allow those libraries to work in cc guests :)
Again, why would you want anyone to access /dev/mem/ at all in those
types of situations?
greg k-h
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 16:00 [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests Nikolay Borisov
2026-11-24 16:29 ` Arnd Bergmann
2026-11-24 16:36 ` Dave Hansen
@ 2026-11-25 16:01 ` sashiko-bot
2026-11-26 8:28 ` Nikolay Borisov
3 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-11-25 16:01 UTC (permalink / raw)
To: Nikolay Borisov, x86
Cc: mhocko, kas, ljs, linux-mm, Dan Williams, Kees Cook, Ingo Molnar,
Vishal Annapurve, Kirill Shutemov, Arnd Bergmann,
Greg Kroah-Hartman, Michael Ellerman, Suzuki K Poulose,
Dave Hansen, Naveen N Rao (AMD)
Thank you for your contribution! Sashiko AI review found 2 potential
issues to consider:
- [Medium] x86/kconfig: unmet DEVMEM dependency when selecting
STRICT_DEVMEM
- [Medium] char/mem: confidential guest check in open_port() blocks
/dev/port
--
commit 044352a94dad5df8ad0a8efbc1156eb4b277903b
Author: Dan Williams <djbw@kernel.org>
x86/devmem: Drop /dev/mem access for confidential guests
This commit selects STRICT_DEVMEM and IO_STRICT_DEVMEM for INTEL_TDX_GUEST
and AMD_MEM_ENCRYPT, and blocks opening /dev/mem in confidential guests by
returning -EPERM when CC_ATTR_GUEST_MEM_ENCRYPT is active.
Link: https://sources.debian.org/src/libdebian-installer/0.125/src/system/subarch-x86-linux.c/?hl=113#L93 [2]
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 58dce0b66179b..7a212f8363e35 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -901,6 +901,8 @@ config INTEL_TDX_GUEST
> depends on X86_X2APIC
> depends on EFI_STUB
> depends on PARAVIRT
> + select STRICT_DEVMEM
> + select IO_STRICT_DEVMEM
> select ARCH_HAS_CC_PLATFORM
> select X86_MEM_ENCRYPT
> select X86_MCE
> @@ -1490,6 +1492,8 @@ 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
> + select IO_STRICT_DEVMEM
> select DMA_COHERENT_POOL
> select ARCH_USE_MEMREMAP_PROT
> select INSTRUCTION_DECODER
[Severity: Medium]
Does selecting STRICT_DEVMEM and IO_STRICT_DEVMEM here trigger an unmet
direct dependency warning when CONFIG_DEVMEM is disabled?
In lib/Kconfig.debug, STRICT_DEVMEM depends on MMU && DEVMEM, and
IO_STRICT_DEVMEM depends on STRICT_DEVMEM. Because DEVMEM is an
independent user-configurable option, building with CONFIG_DEVMEM=n and
either CONFIG_INTEL_TDX_GUEST=y or CONFIG_AMD_MEM_ENCRYPT=y warns on
unmet direct dependencies for STRICT_DEVMEM (and fails the configuration
step under KCONFIG_WERROR).
Note that simply gating the selects with "if DEVMEM" would leave
CONFIG_IO_STRICT_DEVMEM disabled when CONFIG_DEVMEM=n, which would leave
iomem_is_exclusive() inactive for PCI sysfs MMIO mappings unless
STRICT_DEVMEM also drops its dependency on DEVMEM.
> diff --git a/mm/char-mem.c b/mm/char-mem.c
> index 53ce0034a4c13..c06970238bf49 100644
> --- a/mm/char-mem.c
> +++ b/mm/char-mem.c
[ ... ]
> @@ -609,6 +610,15 @@ static int open_port(struct inode *inode, struct file *filp)
> if (rc)
> return rc;
>
> + /*
> + * Enforce encrypted mapping consistency and avoid unaccepted
> + * memory conflicts, "lockdown" /dev/mem for confidential
> + * guests.
> + */
> + if (IS_ENABLED(CONFIG_STRICT_DEVMEM) &&
> + cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> + return -EPERM;
> +
> if (iminor(inode) != DEVMEM_MINOR)
> return 0;
[Severity: Medium]
Does placing this check before the DEVMEM_MINOR check unintentionally
block /dev/port in confidential guests as well?
open_port() is shared as the .open handler for both mem_fops (/dev/mem)
and port_fops (/dev/port). Because the CC_ATTR_GUEST_MEM_ENCRYPT check runs
before "if (iminor(inode) != DEVMEM_MINOR) return 0;", opening /dev/port
will also fail with -EPERM whenever CONFIG_STRICT_DEVMEM is enabled.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261124160025.738362-2-nik.borisov@suse.com?part=1
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 17:57 ` Nikolay Borisov
@ 2026-11-25 16:51 ` Naveen N Rao
2026-11-26 7:17 ` Nikolay Borisov
0 siblings, 1 reply; 12+ messages in thread
From: Naveen N Rao @ 2026-11-25 16:51 UTC (permalink / raw)
To: Nikolay Borisov
Cc: Pedro Falcato, Dave Hansen, x86, mhocko, linux-mm, linux-kernel,
Kees Cook, Ingo Molnar, Vishal Annapurve, Kirill Shutemov,
Arnd Bergmann, Greg Kroah-Hartman, Michael Ellerman,
Suzuki K Poulose, Dave Hansen, Liam R. Howlett, Andrew Morton,
Lorenzo Stoakes, Vlastimil Babka, David Hildenbrand
On Tue, Nov 24, 2026 at 07:57:05PM +0200, Nikolay Borisov wrote:
> On 24.11.26 г. 19:10 ч., Pedro Falcato wrote:
> > On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
> > > On 11/24/26 08:00, Nikolay Borisov wrote:
>
> > 2) open-codes random CC checks in mm, which is kind-of regrettable
> >
> > OTOH, it's unclear to me why that CC check is needed. If configs select
> > STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
> > in iomem_is_exclusive, etc. If not, could the CC awareness sit there
> > instead?
>
> Well, you are right that if we retain just the select
> STRICT_DEVMEM/IO_STRICT_DEVMEM it might fix the immediate issue. I don't
> know why eventually Dan decided to also add this check, I guess it's an
> instance of "fail fast".
Actually no? On x86, devmem_is_allowed() allows access to the first 1 MB
area, so STRICT_DEVMEM alone isn't sufficient.
- Naveen
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-25 16:51 ` Naveen N Rao
@ 2026-11-26 7:17 ` Nikolay Borisov
0 siblings, 0 replies; 12+ messages in thread
From: Nikolay Borisov @ 2026-11-26 7:17 UTC (permalink / raw)
To: Naveen N Rao
Cc: Pedro Falcato, Dave Hansen, x86, mhocko, linux-mm, linux-kernel,
Kees Cook, Ingo Molnar, Vishal Annapurve, Kirill Shutemov,
Arnd Bergmann, Greg Kroah-Hartman, Michael Ellerman,
Suzuki K Poulose, Dave Hansen, Liam R. Howlett, Andrew Morton,
Lorenzo Stoakes, Vlastimil Babka, David Hildenbrand
On 25.11.26 г. 18:51 ч., Naveen N Rao wrote:
> On Tue, Nov 24, 2026 at 07:57:05PM +0200, Nikolay Borisov wrote:
>> On 24.11.26 г. 19:10 ч., Pedro Falcato wrote:
>>> On Tue, Nov 24, 2026 at 08:36:45AM -0800, Dave Hansen wrote:
>>>> On 11/24/26 08:00, Nikolay Borisov wrote:
>>
>>> 2) open-codes random CC checks in mm, which is kind-of regrettable
>>>
>>> OTOH, it's unclear to me why that CC check is needed. If configs select
>>> STRICT_DEVMEM and IO_STRICT_DEVMEM, shouldn't it Just Do The Right thing?
>>> in iomem_is_exclusive, etc. If not, could the CC awareness sit there
>>> instead?
>>
>> Well, you are right that if we retain just the select
>> STRICT_DEVMEM/IO_STRICT_DEVMEM it might fix the immediate issue. I don't
>> know why eventually Dan decided to also add this check, I guess it's an
>> instance of "fail fast".
>
> Actually no? On x86, devmem_is_allowed() allows access to the first 1 MB
> area, so STRICT_DEVMEM alone isn't sufficient.
For the first megabyte of memory (BIOS) is return 2, meaning "Just
return 0, rather than trying to access the address range".
>
>
> - Naveen
>
^ permalink raw reply [flat|nested] 12+ messages in thread
* Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
2026-11-24 16:00 [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests Nikolay Borisov
` (2 preceding siblings ...)
2026-11-25 16:01 ` sashiko-bot
@ 2026-11-26 8:28 ` Nikolay Borisov
3 siblings, 0 replies; 12+ messages in thread
From: Nikolay Borisov @ 2026-11-26 8:28 UTC (permalink / raw)
To: x86
Cc: mhocko, kas, ljs, linux-mm, linux-kernel, Kees Cook, Ingo Molnar,
Vishal Annapurve, Kirill Shutemov, Arnd Bergmann,
Greg Kroah-Hartman, Michael Ellerman, Suzuki K Poulose,
Dave Hansen, Naveen N Rao (AMD), Pedro Falcato
On 24.11.26 г. 18:00 ч., Nikolay Borisov wrote:
> From: Dan Williams <dan.j.williams@intel.com>
>
> 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 arrange for /dev/mem to always behave as
> if lockdown is enabled 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.
>
> Cc: x86@kernel.org
> Cc: Kees Cook <kees@kernel.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: Vishal Annapurve <vannapurve@google.com>
> Cc: Kirill Shutemov <kirill.shutemov@linux.intel.com>
> Cc: Arnd Bergmann <arnd@arndb.de>
> Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
> Cc: Michael Ellerman <mpe@ellerman.id.au>
> Cc: Suzuki K Poulose <suzuki.poulose@arm.com>
> Link: https://sources.debian.org/src/libdebian-installer/0.125/src/system/subarch-x86-linux.c/?hl=113#L93 [2]
> Reported-by: Nikolay Borisov <nik.borisov@suse.com>
> Closes: http://lore.kernel.org/20250318113604.297726-1-nik.borisov@suse.com [1]
> Fixes: 9aa6ea69852c ("x86/tdx: Make pages shared in ioremap()")
> Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
> Reviewed-by: Nikolay Borisov <nik.borisov@suse.com>
> Acked-by: Naveen N Rao (AMD) <naveen@kernel.org>
> Tested-by: Naveen N Rao (AMD) <naveen@kernel.org>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> Signed-off-by: Nikolay Borisov <nik.borisov@suse.com>
> ---
>
> Resending this with the hope of either getting it accepted or arriving at a consensus
> what exactly is missing so that I can take it from there and eventually get something
> merged. As previously mentioned this results in real problems for confidential
> guests both on TDX as well as SEV-SNP.
>
> arch/x86/Kconfig | 4 ++++
> mm/char-mem.c | 10 ++++++++++
> 2 files changed, 14 insertions(+)
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 3159852fd6b3..1490e0019c71 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -901,6 +901,8 @@ config INTEL_TDX_GUEST
> depends on X86_X2APIC
> depends on EFI_STUB
> depends on PARAVIRT
> + select STRICT_DEVMEM
> + select IO_STRICT_DEVMEM
> select ARCH_HAS_CC_PLATFORM
> select X86_MEM_ENCRYPT
> select X86_MCE
> @@ -1490,6 +1492,8 @@ 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
> + select IO_STRICT_DEVMEM
> select DMA_COHERENT_POOL
> select ARCH_USE_MEMREMAP_PROT
> select INSTRUCTION_DECODER
> diff --git a/mm/char-mem.c b/mm/char-mem.c
> index c5761ddedbd7..5d383befd87d 100644
> --- a/mm/char-mem.c
> +++ b/mm/char-mem.c
> @@ -30,6 +30,7 @@
> #include <linux/uio.h>
> #include <linux/uaccess.h>
> #include <linux/security.h>
> +#include <linux/cc_platform.h>
>
> #include "internal.h"
>
> @@ -609,6 +610,15 @@ static int open_port(struct inode *inode, struct file *filp)
> if (rc)
> return rc;
>
> + /*
> + * Enforce encrypted mapping consistency and avoid unaccepted
> + * memory conflicts, "lockdown" /dev/mem for confidential
> + * guests.
> + */
> + if (IS_ENABLED(CONFIG_STRICT_DEVMEM) &&
> + cc_platform_has(CC_ATTR_GUEST_MEM_ENCRYPT))
> + return -EPERM;
> +
> if (iminor(inode) != DEVMEM_MINOR)
> return 0;
>
Having taken a 2nd look I think a consensus solution would be if this
check is moved inside devmem_is_allowed() for x86. That way /dev/mem
could be opened but reads will simply return -EPERM. That way
x86-specific checks don't leak into the generic mm code.
> --
> 2.56.0
>
^ permalink raw reply [flat|nested] 12+ messages in thread
end of thread, other threads:[~2026-11-26 8:28 UTC | newest]
Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-24 16:00 [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests Nikolay Borisov
2026-11-24 16:29 ` Arnd Bergmann
2026-11-24 16:36 ` Dave Hansen
2026-11-24 17:10 ` Pedro Falcato
2026-11-24 17:35 ` Greg Kroah-Hartman
2026-11-24 17:53 ` Nikolay Borisov
2026-11-25 5:06 ` Greg Kroah-Hartman
2026-11-24 17:57 ` Nikolay Borisov
2026-11-25 16:51 ` Naveen N Rao
2026-11-26 7:17 ` Nikolay Borisov
2026-11-25 16:01 ` sashiko-bot
2026-11-26 8:28 ` Nikolay Borisov
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox