[PATCH v2 03/23] nitro_enclaves: Request write access to enclave memory regions

From: Alexander Graf

Date: Sun Nov 29 2026 - 13:23:51 EST


NE_SET_USER_MEMORY_REGION takes its page references with
get_user_pages_unlocked() and plain FOLL_GET, which only asks for read
access. The Nitro Enclaves device then writes to those pages for as long
as the enclave owns them. So we accept regions that the calling process
cannot write itself, for example a PROT_READ mapping.

Enclave memory has to be writable by the process that owns it, because
the device writes it. Pass FOLL_WRITE as well, so that
get_user_pages_unlocked() faults the pages in for writing and fails with
-EFAULT when the mapping does not allow writes.

User space can see this change: a region without write permission used
to be accepted and now fails with -EFAULT. Callers that map enclave
memory PROT_READ | PROT_WRITE, like
samples/nitro_enclaves/ne_ioctl_sample.c, are not affected.

Fixes: 7dc9d4309fdb ("nitro_enclaves: Add logic for setting an enclave memory region")
Cc: stable@xxxxxxxxxxxxxxx
Signed-off-by: Alexander Graf <graf@xxxxxxxxxx>
---
drivers/virt/nitro_enclaves/ne_misc_dev.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/virt/nitro_enclaves/ne_misc_dev.c b/drivers/virt/nitro_enclaves/ne_misc_dev.c
index a50dc4f737b55..bb16a35f82fc0 100644
--- a/drivers/virt/nitro_enclaves/ne_misc_dev.c
+++ b/drivers/virt/nitro_enclaves/ne_misc_dev.c
@@ -961,7 +961,7 @@ static int ne_set_user_memory_region_ioctl(struct ne_enclave *ne_enclave,
}

gup_rc = get_user_pages_unlocked(mem_region.userspace_addr + memory_size, 1,
- ne_mem_region->pages + i, FOLL_GET);
+ ne_mem_region->pages + i, FOLL_GET | FOLL_WRITE);

if (gup_rc != 1) {
rc = gup_rc < 0 ? gup_rc : -EFAULT;
--
2.47.1