[RFC PATCH 3/6] um: install guest mappings via pidfd_mmap() in seccomp mode
Cong Wang
xiyou.wangcong at gmail.com
Fri Jul 10 13:53:21 PDT 2026
From: Cong Wang <cwang at multikernel.io>
In SECCOMP mode, map()/unmap() now install into the stub's address
space directly from the monitor via pidfd_mmap()/pidfd_munmap(),
resolving the physmem fd in the monitor's own fd table. The stub neither
receives the fd nor executes mmap/munmap itself.
The ptrace (SKAS0) mode is unchanged: it keeps batching STUB_SYSCALL_MMAP
/MUNMAP for the stub to execute, which works on any host kernel and
needs no new syscall. Only the seccomp path, where the stub is
sandboxed, is converted.
Assisted-by: Claude:claude-opus-4.8
Signed-off-by: Cong Wang <cwang at multikernel.io>
---
arch/um/os-Linux/skas/mem.c | 24 ++++++++++++++++++++++++
1 file changed, 24 insertions(+)
diff --git a/arch/um/os-Linux/skas/mem.c b/arch/um/os-Linux/skas/mem.c
index 8b9921ac3ef8..f751a1ea1c4c 100644
--- a/arch/um/os-Linux/skas/mem.c
+++ b/arch/um/os-Linux/skas/mem.c
@@ -9,6 +9,8 @@
#include <errno.h>
#include <string.h>
#include <sys/mman.h>
+#include <sys/syscall.h>
+#include <linux/pidfd.h>
#include <init.h>
#include <as-layout.h>
#include <mm_id.h>
@@ -236,6 +238,21 @@ int map(struct mm_id *mm_idp, unsigned long virt, unsigned long len, int prot,
{
struct stub_syscall *sc;
+ if (using_seccomp) {
+ struct pidfd_mmap_args args = {
+ .size = sizeof(args),
+ .addr = virt,
+ .len = len,
+ .prot = prot,
+ .flags = MAP_SHARED | MAP_FIXED,
+ .pgoff = offset >> UM_KERN_PAGE_SHIFT,
+ .fd = phys_fd,
+ };
+ long res = syscall(__NR_pidfd_mmap, mm_idp->stub_pidfd, &args, 0);
+
+ return res < 0 ? -errno : 0;
+ }
+
/* Compress with previous syscall if that is possible */
sc = syscall_stub_get_previous(mm_idp, STUB_SYSCALL_MMAP, virt);
if (sc && sc->mem.prot == prot &&
@@ -268,6 +285,13 @@ int unmap(struct mm_id *mm_idp, unsigned long addr, unsigned long len)
{
struct stub_syscall *sc;
+ if (using_seccomp) {
+ long res = syscall(__NR_pidfd_munmap, mm_idp->stub_pidfd,
+ addr, len);
+
+ return res < 0 ? -errno : 0;
+ }
+
/* Compress with previous syscall if that is possible */
sc = syscall_stub_get_previous(mm_idp, STUB_SYSCALL_MUNMAP, addr);
if (sc) {
--
2.43.0
More information about the linux-um
mailing list