From: "David Hildenbrand (Arm)" <david@kernel.org>
To: "Edgecombe, Rick P" <rick.p.edgecombe@intel.com>,
"jgg@nvidia.com" <jgg@nvidia.com>,
"Hansen, Dave" <dave.hansen@intel.com>,
"akpm@linux-foundation.org" <akpm@linux-foundation.org>
Cc: "ljs@kernel.org" <ljs@kernel.org>,
"dave.hansen@linux.intel.com" <dave.hansen@linux.intel.com>,
"linux-mm@kvack.org" <linux-mm@kvack.org>,
"kernel-team@meta.com" <kernel-team@meta.com>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
"rppt@kernel.org" <rppt@kernel.org>,
"bp@alien8.de" <bp@alien8.de>, "kas@kernel.org" <kas@kernel.org>,
"leon@kernel.org" <leon@kernel.org>,
"stable@vger.kernel.org" <stable@vger.kernel.org>,
"gourry@gourry.net" <gourry@gourry.net>
Subject: Re: [PATCH] mm/hmm: reject shadow-stack mappings
Date: Thu, 19 Nov 2026 23:19:40 +0100 [thread overview]
Message-ID: <421ee488-e2a1-4deb-9ffb-7fc712c811de@kernel.org> (raw)
In-Reply-To: <0c6fcb3daeab0ab3df0593cf389124e38e1d7f3f.camel@intel.com>
On 11/19/26 21:40, Edgecombe, Rick P wrote:
> 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...
Gah, nak,
pte_write() just says "something might be able to write to it".
If that's actually true depends on other factors. Like the access+dirty on HW
that manages that in software.
I repeat: *no code* in Linux besides core-mm should ever interpret "pte_write()"
as "cool, I can write to it". The exception is GUP and unfortunately HMM.
--
Cheers,
David
next prev parent reply other threads:[~2026-11-19 22:19 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-13 19:55 Gregory Price (Meta)
2026-11-13 19:57 ` Lorenzo Stoakes (ARM)
2026-11-13 20:15 ` Gregory Price (Meta)
2026-11-13 20:03 ` Jason Gunthorpe
2026-11-13 20:41 ` Gregory Price (Meta)
2026-11-14 0:20 ` Jason Gunthorpe
2026-11-14 2:10 ` Andrew Morton
2026-11-15 0:00 ` Jason Gunthorpe
2026-11-15 1:01 ` Andrew Morton
2026-11-15 23:27 ` Jason Gunthorpe
2026-11-19 20:05 ` Dave Hansen
2026-11-19 20:16 ` David Hildenbrand (Arm)
2026-11-19 20:40 ` Edgecombe, Rick P
2026-11-19 22:19 ` David Hildenbrand (Arm) [this message]
2026-11-19 20:33 ` Edgecombe, Rick P
2026-11-14 7:25 ` Gregory Price (Meta)
2026-11-14 11:11 ` David Hildenbrand (Arm)
2026-11-15 23:48 ` Alistair Popple
2026-11-16 16:09 ` Gregory Price (Meta)
2026-11-13 20:03 ` David Hildenbrand (Arm)
2026-11-13 20:42 ` Gregory Price (Meta)
2026-11-13 21:19 ` David Hildenbrand (Arm)
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=421ee488-e2a1-4deb-9ffb-7fc712c811de@kernel.org \
--to=david@kernel.org \
--cc=akpm@linux-foundation.org \
--cc=bp@alien8.de \
--cc=dave.hansen@intel.com \
--cc=dave.hansen@linux.intel.com \
--cc=gourry@gourry.net \
--cc=jgg@nvidia.com \
--cc=kas@kernel.org \
--cc=kernel-team@meta.com \
--cc=leon@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-mm@kvack.org \
--cc=ljs@kernel.org \
--cc=rick.p.edgecombe@intel.com \
--cc=rppt@kernel.org \
--cc=stable@vger.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®