From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id nwvlADc4HWBBGQAA0tVLHw (envelope-from ) for ; Fri, 05 Feb 2021 12:21:11 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id 8FupNzY4HWBqbwAAB5/wlQ (envelope-from ) for ; Fri, 05 Feb 2021 12:21:10 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 649239404C7 for ; Fri, 5 Feb 2021 12:21:10 +0000 (UTC) Received: from localhost ([::1]:41594 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1l806n-000731-8H for larch@yhetil.org; Fri, 05 Feb 2021 07:21:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:42430) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1l806e-00072t-2E for guix-devel@gnu.org; Fri, 05 Feb 2021 07:21:00 -0500 Received: from baptiste.telenet-ops.be ([2a02:1800:120:4::f00:13]:51400) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1l806X-0005VZ-Te for guix-devel@gnu.org; Fri, 05 Feb 2021 07:20:59 -0500 Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by baptiste.telenet-ops.be with bizsmtp id RQLm2400G0mfAB401QLm7C; Fri, 05 Feb 2021 13:20:46 +0100 Message-ID: <56adb5efa894304c27beba99b07e2f8cfd8ee7cb.camel@telenet.be> Subject: Re: Potential security weakness in Guix services From: Maxime Devos To: Ludovic =?ISO-8859-1?Q?Court=E8s?= Date: Fri, 05 Feb 2021 13:20:40 +0100 In-Reply-To: <87v9b66dm1.fsf@gnu.org> References: <87k0rrls0z.fsf@gnu.org> <08F0CD76-DDCF-4CFA-AE8D-5FB165A62B25@lepiller.eu> <87o8h2ehy7.fsf@gnu.org> <69968b3a01d872cabdf55a94b6c82d5057e010c9.camel@telenet.be> <87v9b66dm1.fsf@gnu.org> Content-Type: multipart/signed; micalg="pgp-sha256"; protocol="application/pgp-signature"; boundary="=-z0cwz62wnBKoXHPFgvvh" User-Agent: Evolution 3.34.2 MIME-Version: 1.0 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=telenet.be; s=r21; t=1612527647; bh=DSq8QhkYiD9bM4/xmP7cQehJkiNKVkrxABxNtoH9Ss8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=m2cUBOqCY8kBg7+5CpOU78U3R5XPc3adWK8xCV+Xc0UZD749tqA6mxb+p9zlLFRbi mOACTO3tOBi8My7hq5AxXw3FsyYjW4dqnWKUrCHgpZhp8PIX+pa7pjAw2abqj6FpZM 03tNa40b4TGuhOsDIL5YdnMWNZEiNqArMNltBIX3SO8cTZcaWahMGc4qCVuBwhq8mp 9i+ImbLyMQXHwtzeAIrf3akwcXHWUgiEYwHHdTNiQufiFnA1EuDuN2kSop/mCcuXDE ZiTefmHHRXsgEUpU2JfiPRtdnloiQHf8yQiQpr2BU1wsI8VlKwEA0IXjjprxLg1W51 uvh05PdwOD9Bw== Received-SPF: pass client-ip=2a02:1800:120:4::f00:13; envelope-from=maximedevos@telenet.be; helo=baptiste.telenet-ops.be X-Spam_score_int: -27 X-Spam_score: -2.8 X-Spam_bar: -- X-Spam_report: (-2.8 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, RCVD_IN_DNSWL_LOW=-0.7, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guix-devel@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: "Development of GNU Guix and the GNU System distribution." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: guix-devel@gnu.org Errors-To: guix-devel-bounces+larch=yhetil.org@gnu.org Sender: "Guix-devel" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: -3.35 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=m2cUBOqC; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-devel-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-devel-bounces@gnu.org X-Migadu-Queue-Id: 649239404C7 X-Spam-Score: -3.35 X-Migadu-Scanner: scn0.migadu.com X-TUID: axtOpgU64XCD --=-z0cwz62wnBKoXHPFgvvh Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, 2021-02-05 at 10:57 +0100, Ludovic Court=C3=A8s wrote: > Hi Maxime, >=20 > > I don't know how I should implement this properly in Guile, though. > > In C, I would use loop using openat with O_NOFOLLOW, in combination > > with stat, but Guile doesn't have openat or O_NOFOLLOW. >=20 > In this case we need a solution without openat for now. Perhaps simply > changing =E2=80=98mkdir-p/perms=E2=80=99 to =E2=80=98lstat=E2=80=99 compo= nents as it goes? A compromised service could create a component as a regular file or directory, and quickly replace it with a symlink after the activation gexp checks the component wasn't a symlink but before the chown or chmod. It's a tiny window though. I was going to say this tiny =E2=80=98exploitat= ion window=E2=80=99 could be ignored for now until an API to openat & other *at C functions makes it into guile, but then I checked the inotify(7) API. Apparently, inotify events are generated for directory accesses. > > [...] > > I'll look into writing a concrete proposal for *at in guile. > > I'll post a link to the guile mailing list message when it has > > been composed and sent. Link: https://lists.gnu.org/archive/html/bug-guile/2021-02/msg00002.html > The difficulty in designing such an interface is that the Scheme API is > more about ports than it=E2=80=99s about file names and file descriptors. This doesn't seem a large issue to me. Ports for directories can be made with 'open': (open "/home" O_RDONLY). Example use of for changing permission bits of "/home/USER" with proposed API: (let* ((directory (open "/home" O_RDONLY)) ;; in the C API, this translates to: ;; openat(directory-fd, "USER", O_IDK) ;; (replace O_IDK with appropriate open flags) (file-in-dir (open (make-path-at directory "USER") O_IDK))) (chmod file-in-dir #o077) (chown file-in-dir 0 0)) I'll try to implement this API in Scheme (using the FFI), and post it at https://notabug.org/mdevos/things. I'll post a follow-up messsage once I've implemented the basics (openat, chmodat, chownat). Greetings, Maxime. --=-z0cwz62wnBKoXHPFgvvh Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYIADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYB04GBccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7sAPAP9WCEjKyVq+ivOLK+zH06E3MAD1 xLRIvTQaherGK12EQQD/SNjAoWr30fedsUFp8c38oBxysQrg1FykpN3qqR82lg4= =mnx2 -----END PGP SIGNATURE----- --=-z0cwz62wnBKoXHPFgvvh--