From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f50.google.com (mail-pj1-f50.google.com [209.85.216.50]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA1B43AEF3F for ; Fri, 10 Jul 2026 20:54:00 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.50 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783716843; cv=none; b=hjxH7VnxxH2kFM3qp2yVdp9j9bFYZvp4vHthdyE+3cMgOzyB89IPsOh/RpjhebGP5NpteqvTQgRc3e74RhKL3tcZrdYG4p1SsMcL+1ZUPYGYTWSFBCWn8etiRZt52Gc3PXgCb0VnP6BJjtSEGWbcfojFqE+tu+xPw7zhdPwl37Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1783716843; c=relaxed/simple; bh=8qAqz7cg5f8GkHTrwDXGFOM6ENG8y+b2fi75L4bJTLs=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=pQzaPc+tmD1Ufce9whWXki/a/kDR16t83ym0qNlB6fdmDve0VnIuNaCcudJsmwX++yRI7PetscLFSy02v0lldZ4hAGrs7b5mye4O4XRzNWiDv7VzC+BcmUc3Vlhwsa09pLsnDjS9Taqu/MsqeuSVdhHDMZdMNqe7wgq0W0/i9D4= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=DE+ajnQH; arc=none smtp.client-ip=209.85.216.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="DE+ajnQH" Received: by mail-pj1-f50.google.com with SMTP id 98e67ed59e1d1-36b9d265355so1211341a91.2 for ; Fri, 10 Jul 2026 13:54:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1783716839; x=1784321639; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to:content-type; bh=UWjxCj/TKTNYVdvKD41KqqSUzOm1MXKHzbWV9E2lCOM=; b=DE+ajnQH8HQxXlJIWpQzt/rFuOThFKrQhVisxd/iJNVkFL1PXumBEVWY3vBcFhm7wt cgyxEVKgKezU+TUVjho9Ik9fjNGE3lWXo9jcQdM4G0Z/P+y8dytTBNNY/9JHImshzDun dIKk7/8sTLcXKf6RHvLwM95xD5ha0BhiyRbrrwn4DPYBWJG4/SJi3Bi+oiXZdNb2cAlV RiYlrKQ5jIRSN569RyyKoIUdklcekB3aTLXfBiOznzbKmnW8ANp+EDog23GNCbtEdbWt M1c8WamCe7LE7Q+WZK0J/vA7OKM2ctTQNBlGaXFsL4CnN1b0oG7pZ49WD2tJmngM7boy J4vQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1783716839; x=1784321639; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-gg:x-gm-message-state:from :to:cc:subject:date:message-id:reply-to:content-type; bh=UWjxCj/TKTNYVdvKD41KqqSUzOm1MXKHzbWV9E2lCOM=; b=EDLGExD9/Jx6mEv6+EkxqdwWrYe7Q+/cLCW+nXB5zessRXuVMD3hDiIvyXwNenCkiK E1u7pB8KYGUiyg69Lik1iyuaArmYpZEgGRkrtDuTDMAc+VFEzsx3lQS6M9ba/VmZmGf7 BMNYqCWCF1r3HYpmtgaKKiJ8hJ2B+r1hCuoI1E/xlEuH3cTBW+xEUpzJSK4vxGN2IbWo ZcpoTKDXRBZq/zyhCVuzo1suQasqCK9xcWWRdaMuI7Gw/g6cM96iM2PaTS6xRCncqr39 an9WSUnEN+St8G55UMRrjrZ98alBezmhyZB40X0zRURpb9FYfEI0Keq2RcH4INOOdc56 zbnw== X-Forwarded-Encrypted: i=1; AHgh+RoJJPJNSv0rDOAXjnU0gTwBPUVOHQhbkjR0ijPcJ4iDB8Xcft2DYLkJ9smPInIfhvKDd4jIZy+5caermnU=@vger.kernel.org X-Gm-Message-State: AOJu0YzGysQIL3112dsBybGgjH7oc9YujGYgjAhCKZCDJEa7GxufHolX 4H26ddknR73OtVCpiZPNvmzr0IVx/uBw9CG7gD2shu/84DXvYHdrAdzr X-Gm-Gg: AfdE7ckfOgcNYDhEaeaLuguoqj5jvXIkU+VLx7GCMIqoMOR0GEKZZf1qFKpVd1BiUxw vUv7RJ02NFnUWFD/YE6SURcZWwXEwvXG2UTq6qaecpprKS9OwW9XPzSf/eu0Zf/KDS19vo34jlr g20CzXXUPLnkYRgDUiLyxVLaue4mnS0KplZgx30a7UmLNOd7y/oBmgOEBXHJb8OuMR1JfBArthr sD7XWoGMVTaukXI+4TrurgRu1G1G0HNYHzwXZ2amOPBtPX8Yz88Smc63SH0dxWJYNs3NAQIuW41 a9s7PLYF7J5sKnWZGdM6mKkUdrno6huZN9G+sxWQWXNenwllspTuG8QGDTYIoTegsA2NegAMjFd FQ0MzUi8rMvrT+vq8uVFvCCqbUzuqxQXARIzk8CHcadgSQV7rM3Vu/tNx3HdabNax7LjAK92MK/ +W9lg4g9PtzllUh10GibRO/ZYph5j3BBF8JivX45Ydu3hRVx70etT6ABg= X-Received: by 2002:a17:90b:5583:b0:383:f52b:d616 with SMTP id 98e67ed59e1d1-38dc75e3a5fmr461534a91.10.1783716839175; Fri, 10 Jul 2026 13:53:59 -0700 (PDT) Received: from pop-os.scu.edu ([129.210.115.107]) by smtp.gmail.com with ESMTPSA id 5a478bee46e88-3119c2a7bb5sm21724371eec.25.2026.07.10.13.53.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 10 Jul 2026 13:53:58 -0700 (PDT) From: Cong Wang To: Richard Weinberger , Anton Ivanov , Johannes Berg Cc: Benjamin Berg , linux-um@lists.infradead.org, linux-kernel@vger.kernel.org, Cong Wang Subject: [RFC PATCH 3/6] um: install guest mappings via pidfd_mmap() in seccomp mode Date: Fri, 10 Jul 2026 13:53:21 -0700 Message-ID: <20260710205324.1343217-4-xiyou.wangcong@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20260710205324.1343217-1-xiyou.wangcong@gmail.com> References: <20260710205324.1343217-1-xiyou.wangcong@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Cong Wang 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 --- 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 #include #include +#include +#include #include #include #include @@ -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