From patchwork Mon Mar 17 17:02:52 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: 40293 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 119BC27BBE9; Mon, 17 Mar 2025 17:07:01 +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 autolearn=unavailable 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 BF16B27BBE2 for ; Mon, 17 Mar 2025 17:07:00 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tuDu1-0005EX-5h; Mon, 17 Mar 2025 13:05:25 -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 1tuDtw-0005CD-RT for guix-patches@gnu.org; Mon, 17 Mar 2025 13:05:21 -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 1tuDtw-0005ia-Hd for guix-patches@gnu.org; Mon, 17 Mar 2025 13:05:20 -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=ZFzrFk7nTXhAfaat5FBy/2gARokuQM84I/u4c9YnLJQ=; b=nwHMQue08ZeHkOb30OhJZpY8m4zTxxkn9MiOXKO4um5US8Ky8aLIWPEHIk2dvcDQmFXFFVUZkdMFi3GmE/AqHGuinKUXdWBrLpyRBfp3o4tVd/BbWcq9XAmqdgMm1dHpVH03dqNHZ7Z4A8vse7pjubkYQkwCw23glPKrEGg5SR5LtKUQ4KBhzGVpiT4p4MW/Lhok8nXivvmexfrZqnhR5pJK1iKRn414GsisvoU+VBwDtHS4a+xAMeKm/9bNj/JekjTYhDMrEnhEWnxlUWw3Lua/UDcKuJAtbEEau+lj2zZ+3Mjv6QQKkrWz7ku2ZoYkK+Irrz7VI5c8R+36IMlDSw==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tuDtu-0002tf-2O for guix-patches@gnu.org; Mon, 17 Mar 2025 13:05:18 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#75810] [PATCH v6 09/16] 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: Mon, 17 Mar 2025 17:05:17 +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.174223110510712 (code B ref 75810); Mon, 17 Mar 2025 17:05:17 +0000 Received: (at 75810) by debbugs.gnu.org; 17 Mar 2025 17:05:05 +0000 Received: from localhost ([127.0.0.1]:60677 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tuDtf-0002mQ-R8 for submit@debbugs.gnu.org; Mon, 17 Mar 2025 13:05:04 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:36064) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tuDtQ-0002iQ-RC for 75810@debbugs.gnu.org; Mon, 17 Mar 2025 13:04:49 -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 1tuDtJ-0005NP-PS; Mon, 17 Mar 2025 13:04:41 -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=ZFzrFk7nTXhAfaat5FBy/2gARokuQM84I/u4c9YnLJQ=; b=kHFB1Kn5vBHcBokpzK+I /aDH3ixUyNQG4YTRjOkw+KOMU9SKQHNw7PlAIcOOUDD80bBziV78JgJN8YrAT8+/Bp7h7eYbw4lL2 FLpUCue/6xXycBJQzf0LRBFJmTr+Hnf5xBTGfC8oEER+Vc4G8lCmlLuouGErCaG7HaMBhjCtT0YyJ Qa/cAqLcYOgvMa8PaudBLt0IpGO72+divoNw7McqbnQD5sFYORUQcDDIWG4a4Jga67G3izToJ1NWB xxjicemMBw7hBaQpy6n81Zq0kadqUiP8o8SSGTgMwbGxLG8qUAAA1d5kTVUgPnjyNtm5NqgKwUaT8 T7Cu/tiNP9v/Iw==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Mon, 17 Mar 2025 18:02:52 +0100 Message-ID: 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 4e949bc88a..35d9c8cd56 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 9a8278cd08..51ac11e235 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) @@ -2074,6 +2077,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));