Re: [PATCH] mm/hmm: reject shadow-stack mappings

From: Edgecombe, Rick P

Date: Thu Nov 19 2026 - 15:41:01 EST


On Thu, 2026-11-19 at 12:05 -0800, Dave Hansen wrote:
> On 11/14/26 17:01, Andrew Morton wrote:
> > On x86, a shadow-stack PTE has its ordinary write bit clear.  The CPU
> > rejects ordinary stores, but pte_write() reports it writable because
> > shadow-stack instructions can write it.  HMM consequently sets
> > HMM_PFN_WRITE.  Nouveau uses that flag for GPU write permission, and
> > RDMA on-demand paging can use it to grant device write permission to a
> > registered memory region.  A device, or an RDMA peer with write access
> > to that region, can then overwrite the process's shadow stack,
> > potentially corrupting return addresses or bypassing that protection.
> >
> > Reject shadow-stack VMAs in hmm_vma_walk_test(), including read access.
> > A requested fault returns -EFAULT; a snapshot records HMM_PFN_ERROR.
>
> This is a fun one.
>
> I almost wonder if we want to go one step further and disallow GUPs with
> FOLL_WRITE on these PTEs. There should be precious few reasons for
> devices to be writing to shadow stack pages.
>
> Isn't this a bigger issue than HMM? Should the fix be in HMM?

We do reject GUPs to shadow stack PTEs with FOLL_WRITE, unless FOLL_FORCE is
passed. The tricky thing as mentioned my others in this thread is that shadow
stack memory *is* writable by userspace. But also the kernel should not treat it
as such

A false negative for pte_write() is dangerous when the kernel needs to decide
when to revoke access. (i.e. fork) I think a mistake there is somewhat worse
then missing an exotic way to cajole the kernel into writing to a user's shadow
stack like this. So I think pte_write() being true for shadow stacks is the
correct implementation.

But, maybe the problem is that pte_write() is doing the job of two separate
concepts. What if there was a pte_userspace_could_write() and a
pte_kernel_should_not_write()? Names would need some work...