From patchwork Wed Mar 26 16:51:02 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: 40859 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 832C527BBEA; Wed, 26 Mar 2025 16:52:58 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,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 482E027BBE2 for ; Wed, 26 Mar 2025 16:52:58 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1txTzo-0004IO-EV; Wed, 26 Mar 2025 12:52:54 -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 1txTz9-00045M-JM for guix-patches@gnu.org; Wed, 26 Mar 2025 12:52:12 -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 1txTz0-0007WD-5m for guix-patches@gnu.org; Wed, 26 Mar 2025 12:52:02 -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=rc2kZYN8q1ModnvzUaRogE7XUS0CTShYmwMmpQM1NEDgLCmqBGtvYDg83MpnX3F7wy7kW1ZvJRjj9eJYttbCGPbjt9qPbCg6HD38V8gQWMZElOghuSFfkquSAYELpOt5tAsy2QTiX0kjPMfKUMm9xJSIOPcJJ/lX94j3+V9IaIFHBGn3R55WUbZ+aHKzntj2Kgby3MBITJ5V5pyize6Iy9s5bG/Xcn7bzas7O9G1MvFKq7JGXG3uI5vp62/GgF6ssrkWChO2+yHi5/N5RUlqAb2GiipOS6zVDYteJUqVlP4AVwYx6ur8sklF8/Vhuy8QEKKg6wtkedcWhmkzzK/yDg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1txTz0-0000ak-16 for guix-patches@gnu.org; Wed, 26 Mar 2025 12:52:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#77288] [PATCH 1/6] 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: Wed, 26 Mar 2025 16:52:01 +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.17430078942181 (code B ref 77288); Wed, 26 Mar 2025 16:52:01 +0000 Received: (at 77288) by debbugs.gnu.org; 26 Mar 2025 16:51:34 +0000 Received: from localhost ([127.0.0.1]:44139 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1txTyX-0000Z1-ML for submit@debbugs.gnu.org; Wed, 26 Mar 2025 12:51:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:58030) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1txTyU-0000YQ-AV for 77288@debbugs.gnu.org; Wed, 26 Mar 2025 12:51:30 -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 1txTyN-0007L8-VC; Wed, 26 Mar 2025 12:51:23 -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=QqOzJW/sKkFZ/rkpCSHj UJFKphlQs6I+v/y9h8P9/OH1AbzmqTKVX5dQcVGpgbawlPcuwCwQY7ng5ELtQK4WX+nmlrheC7vKr v8N/umwn5qzCz1SEPLRgsfAVejz/JLkBAHZ7iUOoeRm5Me2JX0AnBTq2IdMlVhSL/DoSiDauKAJwf YhSVX/0VitsPoYuKF7WwT5zC1hnYQuT3594UAklOw9jnTeF3dYDEeDXMf3z471hR/VS4oDv/sdtDj HTjlmmQzOW/njV+iV4/NrC/k7PqwpjB/eZq00/rFnJrZIDpfESuD4VwdFrRpkq+1C17To9kj9GJat SqQn08zR97II7A==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Wed, 26 Mar 2025 17:51:02 +0100 Message-ID: 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"