Re: [RESEND PATCH] x86/devmem: Drop /dev/mem access for confidential guests
From: Naveen N Rao
Date: Fri Nov 27 2026 - 04:52:54 EST
On Thu, Nov 26, 2026 at 10:28:02AM +0200, Nikolay Borisov wrote:
>
> > 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.
I arrived at the same conclusion. I believe the reason Dan chose to do
it in open_port() is to mimic lockdown-style semantics so that userspace
could detect and fall back (to using /sys/firmware/dmi/tables, for
instance).
But, as far as I can tell:
(a) userspace should be able to deal with -EPERM from read()/mmap() too,
(b) and the tool failing is better than it crashing, or worse crashing
the guest.
So, I think we can move the check to devmem_is_allowed() and reject all
accesses for CoCo guests.
- Naveen