From: Nikolay Borisov <nik.borisov@suse.com>
To: Dan Williams <dan.j.williams@intel.com>, dave.hansen@linux.intel.com
Cc: x86@kernel.org, Kees Cook <kees@kernel.org>,
Ingo Molnar <mingo@kernel.org>, Naveen N Rao <naveen@kernel.org>,
Vishal Annapurve <vannapurve@google.com>,
Kirill Shutemov <kirill.shutemov@linux.intel.com>,
stable@vger.kernel.org, linux-coco@lists.linux.dev,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH v4 2/2] x86/devmem: Drop /dev/mem access for confidential guests
Date: Tue, 22 Apr 2025 16:38:05 +0300 [thread overview]
Message-ID: <20eaf26f-90e0-44b4-aa4a-ca4aa06be1dd@suse.com> (raw)
In-Reply-To: <174500659632.1583227.11220240508166521765.stgit@dwillia2-xfh.jf.intel.com>
On 18.04.25 г. 23:04 ч., Dan Williams wrote:
> Nikolay reports [1] that accessing BIOS data (first 1MB of the physical
> address space) via /dev/mem results in an SEPT violation.
>
> The cause is ioremap() (via xlate_dev_mem_ptr()) establishes an
> unencrypted mapping where the kernel had established an encrypted
> mapping previously.
>
> Linux traps read(2) access to the BIOS data area, and returns zero.
> However, it turns out the kernel fails to enforce the same via mmap(2).
> This is a hole, and unfortunately userspace has learned to exploit it
> [2].
>
> This means the kernel either needs a mechanism to ensure consistent
> "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.
>
> Cc: <x86@kernel.org>
> Cc: Kees Cook <kees@kernel.org>
> Cc: Ingo Molnar <mingo@kernel.org>
> Cc: "Naveen N Rao" <naveen@kernel.org>
> Cc: Vishal Annapurve <vannapurve@google.com>
> Cc: Kirill Shutemov <kirill.shutemov@linux.intel.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()")
> Cc: <stable@vger.kernel.org>
> Acked-by: Dave Hansen <dave.hansen@linux.intel.com>
> Signed-off-by: Dan Williams <dan.j.williams@intel.com>
> ---
> Changes since v3
> * Fix a 0day kbuild robot report about missing cc_platform.h include.
>
> arch/x86/Kconfig | 4 ++++
> drivers/char/mem.c | 10 ++++++++++
> 2 files changed, 14 insertions(+)
>
> diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
> index 4b9f378e05f6..bf4528d9fd0a 100644
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -891,6 +891,8 @@ config INTEL_TDX_GUEST
> depends on X86_X2APIC
> depends on EFI_STUB
> depends on PARAVIRT
> + depends on STRICT_DEVMEM
> + depends on IO_STRICT_DEVMEM
> select ARCH_HAS_CC_PLATFORM
> select X86_MEM_ENCRYPT
> select X86_MCE
> @@ -1510,6 +1512,8 @@ config AMD_MEM_ENCRYPT
> bool "AMD Secure Memory Encryption (SME) support"
> depends on X86_64 && CPU_SUP_AMD
> depends on EFI_STUB
> + depends on STRICT_DEVMEM
> + depends on IO_STRICT_DEVMEM
> select DMA_COHERENT_POOL
> select ARCH_USE_MEMREMAP_PROT
> select INSTRUCTION_DECODER
> diff --git a/drivers/char/mem.c b/drivers/char/mem.c
> index 48839958b0b1..47729606b817 100644
> --- a/drivers/char/mem.c
> +++ b/drivers/char/mem.c
> @@ -30,6 +30,7 @@
> #include <linux/uio.h>
> #include <linux/uaccess.h>
> #include <linux/security.h>
> +#include <linux/cc_platform.h>
>
> #define DEVMEM_MINOR 1
> #define DEVPORT_MINOR 4
> @@ -595,6 +596,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;
Just confirming - the STRIC_DEVMEM check here is needed in case other
CoCo technologies i.e ARM's CCA or risc-v tvm doesn't depend on it?
Because for the x86 world it's redundant since both implementations
imply STRICT_DEVMEM.
> +
> if (iminor(inode) != DEVMEM_MINOR)
> return 0;
>
>
next prev parent reply other threads:[~2025-04-22 13:38 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-04-17 19:11 [PATCH v3 0/2] Restrict devmem for confidential VMs Dan Williams
2025-04-17 19:12 ` [PATCH v3 1/2] x86/devmem: Remove duplicate range_is_allowed() definition Dan Williams
2025-04-17 19:30 ` Dave Hansen
2025-04-17 19:12 ` [PATCH v3 2/2] x86/devmem: Drop /dev/mem access for confidential guests Dan Williams
2025-04-17 19:33 ` Dave Hansen
2025-04-17 22:31 ` kernel test robot
2025-04-17 23:24 ` kernel test robot
2025-04-18 20:04 ` [PATCH v4 " Dan Williams
2025-04-22 13:38 ` Nikolay Borisov [this message]
2025-04-23 17:18 ` Naveen N Rao
2025-04-23 20:36 ` Dan Williams
2025-04-24 6:35 ` Naveen N Rao
2025-04-28 15:53 ` Dave Hansen
2025-04-28 16:30 ` Jianxiong Gao
2025-04-28 16:36 ` Dave Hansen
2025-05-07 5:44 ` [PATCH v3 " kernel test robot
2025-04-22 14:09 ` [PATCH v3 0/2] Restrict devmem for confidential VMs Nikolay Borisov
2025-04-28 15:50 ` Dave Hansen
2025-04-28 22:48 ` Dan Williams
2025-04-29 0:37 ` Dave Hansen
2025-04-30 15:41 ` Suzuki K Poulose
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20eaf26f-90e0-44b4-aa4a-ca4aa06be1dd@suse.com \
--to=nik.borisov@suse.com \
--cc=dan.j.williams@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=kees@kernel.org \
--cc=kirill.shutemov@linux.intel.com \
--cc=linux-coco@lists.linux.dev \
--cc=linux-kernel@vger.kernel.org \
--cc=mingo@kernel.org \
--cc=naveen@kernel.org \
--cc=stable@vger.kernel.org \
--cc=vannapurve@google.com \
--cc=x86@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®