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

From: Edgecombe, Rick P

Date: Thu Nov 19 2026 - 15:33:53 EST


On Sat, 2026-11-14 at 17:01 -0800, Andrew Morton wrote:
> Thanks.  This?
>
> 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.

BTW, this is not just an x86 thing. Arm and riscv have the same pte_write()
shadow stack behavior for the same reasons. Despite not having the
Write=0,Dirty=1 thing, which *is* weird. But they still try to prevent the
kernel from writing it via logic in gup, etc.