From patchwork Thu Mar 20 20:54:42 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: 40525 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 B788627BBE9; Thu, 20 Mar 2025 20:58: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=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 27A1D27BBE2 for ; Thu, 20 Mar 2025 20:58:09 +0000 (GMT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1tvMxp-000333-TN; Thu, 20 Mar 2025 16:58:05 -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 1tvMxn-0002z9-QD for guix-patches@gnu.org; Thu, 20 Mar 2025 16:58:04 -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 1tvMxn-0002mF-EN for guix-patches@gnu.org; Thu, 20 Mar 2025 16:58:03 -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=vFG6iPVFQp7C1RpVfJcQhN1IdM6ZNKaKsQYqPVGNrlk=; b=MTrJXSOPVGK7yI5THHEwGJvn+TKYu3CTeLcvweCg6Gl5oQCwZm5K295PdhlJa8DgDfOHI9ElsqqVoILnnl9De2ZWA51dvx3m6/Q9N++UNhHJTN7km96BKajQzWjBux31DTQUHznWISys/q9HfHYG9OXwLzj+IttsoH98KX35MibGVVCsI+e64x8JQ1k0nOhJWhSB7rhnEHRr82Nx9K7qlWPK34q3cyeuf4MMOalTCGIR0JE/ZoSk0InMUYHBih6XHpnoPzAKyNGR378JyML74FhxcJBF8IV66K7ZN5sXtNV9b7zJMBrAaw86NCuBtHqua8VLkt6yYBtfLfdZsT9e9Q==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1tvMxn-0006fZ-7d for guix-patches@gnu.org; Thu, 20 Mar 2025 16:58:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#75810] [PATCH v7 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: Thu, 20 Mar 2025 20:58:03 +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.174250423825298 (code B ref 75810); Thu, 20 Mar 2025 20:58:03 +0000 Received: (at 75810) by debbugs.gnu.org; 20 Mar 2025 20:57:18 +0000 Received: from localhost ([127.0.0.1]:59193 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1tvMx3-0006Zp-82 for submit@debbugs.gnu.org; Thu, 20 Mar 2025 16:57:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43252) by debbugs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1tvMwE-0006S8-G0 for 75810@debbugs.gnu.org; Thu, 20 Mar 2025 16:56:29 -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 1tvMw5-0001H7-Pe; Thu, 20 Mar 2025 16:56:20 -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=vFG6iPVFQp7C1RpVfJcQhN1IdM6ZNKaKsQYqPVGNrlk=; b=abyaoCi1w5HjKpcRFl+e HxYOoClTP3qRNWcnDX1/mN/zJzSNy/Lowy1GtbA5IvVS77jzrUS+aD91LRFJWWZLKnUz+qTBMUj9G j9frhXhtCcJSz0FonHP5nxLxF9BD5+NQowXIJUtJvJ7csdMRjgY3IlOcgayFVbtbi+D+jjLt47pxW LQKiCzbIhUibNohHNJIFFZAypIrPY7aOxJaiuRNTMraG4ev9cWyzfbq8lvQqk3QGgLLiKImDU2t+A 5Po7QhBUDzAa9ZX1cmaS//PnAu07wx5w04v09LRxoDXJxcHYmQfkIoOKHVtz3M3qr54il/aA40i56 DvuoX+e6HNVcdQ==; From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Thu, 20 Mar 2025 21:54:42 +0100 Message-ID: <50bb8842d557522b6929215bbd5a721b1fa4c69b.1742503591.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 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 e6cd45aba4..fa0f293aac 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) @@ -2075,6 +2078,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));