From patchwork Thu Apr 17 14:21:38 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 41736 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 5ED5E27BC4B; Thu, 17 Apr 2025 15:24:01 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-6.4 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_DNSWL_BLOCKED, RCVD_IN_VALIDITY_CERTIFIED,RCVD_IN_VALIDITY_RPBL,RCVD_IN_VALIDITY_SAFE, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id 1EAF227BC49 for ; Thu, 17 Apr 2025 15:24:01 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1u5Q9H-0000dl-36; Thu, 17 Apr 2025 10:23:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u5Q8w-0000VF-Ce for guix-patches@gnu.org; Thu, 17 Apr 2025 10:23:08 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1u5Q8v-0001eN-EX for guix-patches@gnu.org; Thu, 17 Apr 2025 10:23:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:References:In-Reply-To:Date:From:To:Subject; bh=pX3LSffILOqR/UkDvibjIkTZohWxhjxg21izy7L/1yo=; b=btEIMIu9V6iaPvZvHj+Jkof/n8EJuP3+Cd/b+YU1iS9pja6V3FHP4+IFBqb3k7E1qEbZmkCGEskIQTe+kI9bdwJ0u2TWtLclF0yDpf9jtPckBTW1xywwZmvuqGw1LuBpWOoIUcnG68Pnwxg4dW9oJm+o21rtvdx5iXlbCwRLUwRSWirWIBNPVLxpDfPL47gz4iwo+1sSPioJCG0VUGNBcNRytb84mxjSmxNVFDrdcR82LLIgpZOTbuTrIWAxSliiisRl+IretABIL0E5I6rLLQB5CqELrMM+uMvmq/SC2+5itMIBBNe0rOqJAdhrQ+4k/kgWpsVLEmH91/M6c4Ur/A==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1u5Q8v-0004vs-8I for guix-patches@gnu.org; Thu, 17 Apr 2025 10:23:05 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77288] [PATCH v2 3/8] syscalls: Add =?utf-8?b?4oCYdW5zaGFyZQ==?= =?utf-8?b?4oCZLg==?= Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Thu, 17 Apr 2025 14:23:05 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 77288 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 77288@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 77288-submit@debbugs.gnu.org id=B77288.174489974518740 (code B ref 77288); Thu, 17 Apr 2025 14:23:05 +0000 Received: (at 77288) by debbugs.gnu.org; 17 Apr 2025 14:22:25 +0000 Received: from localhost ([127.0.0.1]:47994 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1u5Q8G-0004s3-23 for submit@debbugs.gnu.org; Thu, 17 Apr 2025 10:22:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43198) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1u5Q7y-0004p1-H3 for 77288@debbugs.gnu.org; Thu, 17 Apr 2025 10:22:11 -0400 Received: from fencepost.gnu.org ([2001:470:142:3::e]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1u5Q7t-0001TR-4N; Thu, 17 Apr 2025 10:22:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=pX3LSffILOqR/UkDvibjIkTZohWxhjxg21izy7L/1yo=; b=dt5Sl0Xcy7wfhBfPWc3+ 4cVdxWhMnzdprRYtq+eGLTlyyVkHIdAeyEVd53i0F1AxcD7mmz/XARN4SfcevdYlwToYSj5DLmpFd tOhhTACyGZwDhY1+k+0l5MH9TOi+1meNRPGvoBSksvXfzOSQcRUafjRn664dL2+e5ih8IzqhF+lWi H4aTmHdHqlMQZPShoHPfVaMal1G586oXtvjnXyLTpZcXf0IqZXmNnNsgt8X/YWACwxrFR6ZeigdnE d2BUFYSYFiOo0mH9xsTSzAwKJ/lM9N5ZDsi+Suw5N+pour9allAL4NIMvwQDp7AyCFkXVN4RQWC5E gcsaplHBr1hY9Q==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 17 Apr 2025 16:21:38 +0200 Message-ID: <3686350af60a8eb68e7e6453cb258a0f7b747bbf.1744899444.git.ludo@gnu.org> X-Mailer: git-send-email 2.49.0 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches * guix/build/syscalls.scm (unshare): New procedure. Change-Id: I344273b8bdeaa9366334e6e20ee7efc37eb6c8f7 --- guix/build/syscalls.scm | 18 ++++++++++++++++++ tests/syscalls.scm | 9 +++++++++ 2 files changed, 27 insertions(+) diff --git a/guix/build/syscalls.scm b/guix/build/syscalls.scm index 42232fc7f1..cf09cae3a4 100644 --- a/guix/build/syscalls.scm +++ b/guix/build/syscalls.scm @@ -145,6 +145,7 @@ (define-module (guix build syscalls) CLONE_NEWPID CLONE_NEWNET clone + unshare setns kexec-load-file @@ -1213,6 +1214,23 @@ (define clone (list err)) ret))))) +(define unshare + (let ((proc (syscall->procedure int "unshare" (list int)))) + (lambda (flags) + "Disassociate the current process from parts of its execution context +according to FLAGS, which must be a logical or of CLONE_NEW* constants. + +Note that CLONE_NEWUSER requires that the calling process be single-threaded, +which is possible if and only if libgc is running a single marker thread; this +can be achieved by setting the GC_MARKERS environment variable to 1. If the +calling process is multi-threaded, this throws to 'system-error' with EINVAL." + (let-values (((ret err) + (without-automatic-finalization (proc flags)))) + (unless (zero? ret) + (throw 'system-error "unshare" "~a: ~A" + (list flags (strerror err)) + (list err))))))) + (define setns ;; Some systems may be using an old (pre-2.14) version of glibc where there ;; is no 'setns' function available. diff --git a/tests/syscalls.scm b/tests/syscalls.scm index d2848879d7..879c3e4f25 100644 --- a/tests/syscalls.scm +++ b/tests/syscalls.scm @@ -149,6 +149,15 @@ (define perform-container-tests? ((_ . status) (= 42 (status:exit-val status)))))))) +(test-equal "unshare" + EPERM + ;; Unless running as root, (unshare CLONE_NEWNS) returns EPERM. + (catch 'system-error + (lambda () + (unshare CLONE_NEWNS)) + (lambda args + (system-error-errno args)))) + (unless perform-container-tests? (test-skip 1)) (test-assert "setns"