From patchwork Fri Feb 21 13:05:56 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 38906 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 D7CFB27BBEA; Fri, 21 Feb 2025 13:09:10 +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 4978C27BBE2 for ; Fri, 21 Feb 2025 13:09:10 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tlSm8-0005NE-GE; Fri, 21 Feb 2025 08:09:06 -0500 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 1tlSm7-0005N6-63 for guix-patches@gnu.org; Fri, 21 Feb 2025 08:09:03 -0500 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 1tlSm6-0004qy-SB for guix-patches@gnu.org; Fri, 21 Feb 2025 08:09:02 -0500 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=Cq0kaUqqXvShQhQeK/4/6kl4yXtjDCBbINBs6TqgNTE=; b=GtLEpSzqNe35sh8mdpCVu9nRzyM06e/fMQe0X/Eeuh59gx83y9vpmx2eysv3KERiIxLP0qQci9Ht75mdxQwqddl0dNpSERgvqkcniiKlMGB9FtK3Mk6M48wxsv6cLhtU48v28D3w3hoOrhS1lsJds8WCB27mCW9O/OxqBKGnNMnIL38cFHiXF6U3kzsbkIJhc3mbY9VksDhBdToI/OLkiruQ0RBueOWY7qkNsQdGLwedKXEF0jgHktbYE2naMVjppKop/DD3HBr3d2UA2qERhq4VzQuGMU482FfMS9x5/lBWnHep02Pk8k4znT4I86qzXDiCoY113rylGYKBLNlfJg==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tlSm6-0005mW-Jy for guix-patches@gnu.org; Fri, 21 Feb 2025 08:09:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#75810] [PATCH v3 08/11] daemon: Drop Linux ambient capabilities before executing builder. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Fri, 21 Feb 2025 13:09:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 75810 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 75810@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 75810-submit@debbugs.gnu.org id=B75810.174014332922102 (code B ref 75810); Fri, 21 Feb 2025 13:09:02 +0000 Received: (at 75810) by debbugs.gnu.org; 21 Feb 2025 13:08:49 +0000 Received: from localhost ([127.0.0.1]:56688 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tlSls-0005kN-E7 for submit@debbugs.gnu.org; Fri, 21 Feb 2025 08:08:48 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:60062) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tlSjy-0005P7-H9 for 75810@debbugs.gnu.org; Fri, 21 Feb 2025 08:06:55 -0500 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 1tlSjs-0004ZV-TC; Fri, 21 Feb 2025 08:06:45 -0500 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=Cq0kaUqqXvShQhQeK/4/6kl4yXtjDCBbINBs6TqgNTE=; b=qBy9fbjeeW40p79U/07I tihiZE0Kqhyn8pVPYYjilI4BpQy6soiuikg3/imWGzATcvSkTRXHaPKbaglmWchOsryj3gNxv4o+m WLS3gSR7mcG0LJhwswLOSOPstwlzmJt2pywuXSqjxmWxe3d2SlYyrOMyaA2d47G+ya0j9pou5XSka QKPTL4yvZQhgERVKT/inE6kUrTxJTCHyFv1jq/ib1MiooLuiKaY5zGyxuKCzPrKKntdiM3sOsoRkf a3uu7MnHrUhD17ZZIracP2ZlfGFTKg8yzT5fkpnBMlKe0jgtyALeJAAYTPiVl2DXrwTaJDBso0xPn am++1LFfStjnPA==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Fri, 21 Feb 2025 14:05:56 +0100 Message-ID: <41e73aaabf721c22bfde3b0369a8e0d1a5694671.1740142328.git.ludo@gnu.org> X-Mailer: git-send-email 2.48.1 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 * config-daemon.ac: Check for . * nix/libstore/build.cc (DerivationGoal::runChild): When ‘useChroot’ is true, call ‘prctl’ to drop all ambient capabilities. Change-Id: If34637fc508e5fb6d278167f5df7802fc595284f --- config-daemon.ac | 2 +- nix/libstore/build.cc | 9 +++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/config-daemon.ac b/config-daemon.ac index 4e949bc88a3..35d9c8cd56b 100644 --- a/config-daemon.ac +++ b/config-daemon.ac @@ -79,7 +79,7 @@ if test "x$guix_build_daemon" = "xyes"; then dnl Chroot support. AC_CHECK_FUNCS([chroot unshare]) AC_CHECK_HEADERS([sched.h sys/param.h sys/mount.h sys/syscall.h \ - linux/close_range.h]) + linux/close_range.h sys/prctl.h]) if test "x$ac_cv_func_chroot" != "xyes"; then AC_MSG_ERROR(['chroot' function missing, bailing out]) diff --git a/nix/libstore/build.cc b/nix/libstore/build.cc index 107ffcfea06..213ed635933 100644 --- a/nix/libstore/build.cc +++ b/nix/libstore/build.cc @@ -50,6 +50,9 @@ #if HAVE_SCHED_H #include #endif +#if HAVE_SYS_PRCTL_H +#include +#endif #define CHROOT_ENABLED HAVE_CHROOT && HAVE_SYS_MOUNT_H && defined(MS_BIND) && defined(MS_PRIVATE) @@ -2059,6 +2062,12 @@ void DerivationGoal::runChild() #if CHROOT_ENABLED if (useChroot) { +# if HAVE_SYS_PRCTL_H + /* Drop ambient capabilities such as CAP_CHOWN that might have + been granted when starting guix-daemon. */ + prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0); +# endif + if (!fixedOutput) { /* Initialise the loopback interface. */ AutoCloseFD fd(socket(PF_INET, SOCK_DGRAM, IPPROTO_IP));