From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:bcc0::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id 2DUiJd6XfWCJZAAAgWs5BA (envelope-from ) for ; Mon, 19 Apr 2021 16:46:54 +0200 Received: from aspmx1.migadu.com ([2001:41d0:2:bcc0::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id mCi6IN6XfWDETwAAB5/wlQ (envelope-from ) for ; Mon, 19 Apr 2021 14:46:54 +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 0250B9217 for ; Mon, 19 Apr 2021 16:46:54 +0200 (CEST) Received: from localhost ([::1]:40844 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYVAr-0007Tl-6E for larch@yhetil.org; Mon, 19 Apr 2021 10:46:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:41086) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYV6C-0004X9-Tb for guix-patches@gnu.org; Mon, 19 Apr 2021 10:42:06 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40014) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lYV6B-0007dN-Fk for guix-patches@gnu.org; Mon, 19 Apr 2021 10:42:04 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lYV6B-0008K5-CF for guix-patches@gnu.org; Mon, 19 Apr 2021 10:42:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47849] [PATCH 1/1] services: Add a service for the Jami daemon. Resent-From: Maxime Devos Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 19 Apr 2021 14:42:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 47849 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: Maxim Cournoyer Cc: 47849@debbugs.gnu.org Received: via spool by 47849-submit@debbugs.gnu.org id=B47849.161884329531926 (code B ref 47849); Mon, 19 Apr 2021 14:42:03 +0000 Received: (at 47849) by debbugs.gnu.org; 19 Apr 2021 14:41:35 +0000 Received: from localhost ([127.0.0.1]:51554 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYV5i-0008Is-Vc for submit@debbugs.gnu.org; Mon, 19 Apr 2021 10:41:35 -0400 Received: from laurent.telenet-ops.be ([195.130.137.89]:46684) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYV5g-0008Ih-3e for 47849@debbugs.gnu.org; Mon, 19 Apr 2021 10:41:33 -0400 Received: from ptr-bvsjgyjmffd7q9timvx.18120a2.ip6.access.telenet.be ([IPv6:2a02:1811:8c09:9d00:aaf1:9810:a0b8:a55d]) by laurent.telenet-ops.be with bizsmtp id uehW2400K0mfAB401ehWdE; Mon, 19 Apr 2021 16:41:30 +0200 Message-ID: <9fc5f3f454a77ccf2a8e09fa602755166c03abf3.camel@telenet.be> From: Maxime Devos Date: Mon, 19 Apr 2021 16:41:20 +0200 In-Reply-To: <87czuqiiki.fsf@gmail.com> References: <20210417200414.18050-1-maxim.cournoyer@gmail.com> <20210417200617.18182-1-maxim.cournoyer@gmail.com> <1e9354c0744afc2d5d11d3eeecaba31f62e59e65.camel@telenet.be> <87czuqiiki.fsf@gmail.com> Content-Type: multipart/signed; micalg="pgp-sha512"; protocol="application/pgp-signature"; boundary="=-Gs+1+lPGRZJ1CxpmLWgP" 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=1618843290; bh=j3eBlX83M+iPkmNBIj3IP4J4FwuxHMRybjfp15N+mG8=; h=Subject:From:To:Cc:Date:In-Reply-To:References; b=Yci767cQWVN/rdFFN8vlDWXYUjeAIa4/w/aVZaTOcfusH3KZ5RlMPF1MFFqgaaRny uO6dfui+MNU8Nj5mQII2enGtvlJ8g4ITIX23d63e77WNzLaAKSCEHXDbjqq/DvxKWo IhpBrvTPdAJLUwbX5E4a6NDquTu88K9zGwUOi7hW5fidvsXatWSbDS3eeUajmO/DM+ E/NNTmUHhq5qjTj+PmKK7yhSYeNMAnxsDZygEOvMCcfITwh1SwRo3qzIRnXtndCnCf celRSLatsij5X2tAnbE2z1bhbxEMN3saBzmmeLv3S7n46ReHvF5GoFXbqAKt/xTKbp cVuog2ACVY/xg== 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1618843614; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type:resent-cc:resent-from:resent-sender: resent-message-id:in-reply-to:in-reply-to:references:references: list-id:list-help:list-unsubscribe:list-subscribe:list-post: dkim-signature; bh=j3eBlX83M+iPkmNBIj3IP4J4FwuxHMRybjfp15N+mG8=; b=ptqsxNjg5ZwNEBW41jFdIeTBi5Mcs8m1XOOYyQ+VLfBIJJYu3I/1IJdr4ymKMTwFY8qpTp HSMWYeMl4RsFnIO0BauorNkMXXAfY1CJr+oVGirUsWT2d+RXy7mCnJd5YUkDuXhfGneHcq ChXQ5ibwsMck654nrBMkoIE96XmOIXruYLmqH25lOiYPJGez9O2vyawn9HlKfl0kevbXlp JLaQzhRNSzgIK8bHaqBC9/H1jR/cZ0Oy1Ygkv+gMGMrrfdtRE2Uim8Srf/SQW0XlVE9fdf vgZZMyNMv7Is9G67CUGe5LaXqiC+WctNaDCr8buoHtdqK5oMZ/NH2Li4ISQz/A== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618843614; a=rsa-sha256; cv=none; b=LlMb0ypzGEGS8s+SCEjLyQHOEIBSpgsepXW0E4QrizEDjgFSinTLFgZ0iknr//Z3ZrlWRe ImT1MnOttBYZykNHigp0Ejncm3K2nlcxKbvOlIp5dvY+EMkbc2OQdNTuP3XmbkBKC4miMv ulBNpJB1kSfbzL8e7jrr0iIDCyy1L0gu/DXFcZfNaHEkjnyCRmi2ay4yQJXMIxJL5HQ1fX yfEbH/vCHJuaPjo2Bv0+WHXpaWNQ3TALv/RAMY4g93gbe+d17oEOQj9VtAyjrwPV+ow2cZ BpqNK0PrxNBdEaGQ+64YVsrowkTjZWtL4KBC5Jkt3cMiK2GpHTYmewGWzO/hXQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=Yci767cQ; spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Spam-Score: -3.44 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=telenet.be header.s=r21 header.b=Yci767cQ; dmarc=fail reason="SPF not aligned (relaxed)" header.from=telenet.be (policy=none); spf=pass (aspmx1.migadu.com: domain of guix-patches-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=guix-patches-bounces@gnu.org X-Migadu-Queue-Id: 0250B9217 X-Spam-Score: -3.44 X-Migadu-Scanner: scn0.migadu.com X-TUID: cB9kvzlNKfcn --=-Gs+1+lPGRZJ1CxpmLWgP Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Maxim Cournoyer schreef op ma 19-04-2021 om 08:07 [-0400]: > Hi Maxime! >=20 > Maxime Devos writes: >=20 > > Maxim Cournoyer schreef op za 17-04-2021 om 16:06 [-0400]: > > + [...] > > + (delete-file-recursively "/var/lib/jami/account= s")) > >=20 > > You might want to verify whether /var/lib/jami/{.cache,.config,.local/s= hare,.local} > > aren't symbolic links. That way, if the Jami daemon is compromised (du= e to buffer > > overflow --> arbitrary code execution or something), the attacker can't= trick the > > shepherd service into deleting arbitrary directories. >=20 > It would only be able to delete directories that are world writable > though, right? Seems the opportunity to cause damage is limited, but > it's a simple check to add, so I'll do it. Let's step through the relevant code of the shepherd service. (shepherd-service (documentation "Run the Jami daemon.") [blabla] (start #~(lambda args [other stuff] (when [blabla, and a 'catch' form] (delete-file-recursively "/var/lib/jami/.cache/jami") [etcetera]) (let* (([blabla]) (user (passwd:uid [blabla jami user])) (group [likewise])) [blabla] (chown accounts-dir user group))) ;; Start the daemon (define daemon-pid (fork+exec-command [blabla Jami cmdline arguments] #:user "jami" #:group "jami" [blabla])) [blabla])) (stop [blabla])) =20 Remember that the shepherd daemon is run as root (and therefore has read-write-execute access to everything). The 'start' procedure (and 'stop' procedure) are run _within_ the shepherd daemon. Thus, the 'start' gexp is run as root. As the start procedure didn't change the uid/gid from root to something else, (delete-file-recursively "/var/lib/jami/.cache/jami") is run as root. IIUC, root user can read/write anything, ignoring things like "user" and "group". World-writability is not required. > What about if the daemon was > run in a container (your suggestion in a following email, to which I > agree would be a good thing)? It would prevent this kind of attack, > right? I don't see how that would help. It is the _shepherd daemon_ (that runs as root) that runs (delete-file-recursively ...), not the attacker (from within the compromised jami-daemon process). Perhaps this is cleared up by my previous response? If not, please walk me through the attack scenari= o you had in mind that would be thwarted by running the jami-daemon in a cont= ainer. > > Example scenario: > > * the jami daemon has a security bug that allows arbitrary code execu= tion > > within the daemon > > * the attacker exploits this > > * now the attacker can modify everything under /var/lib/jami > > * the attacker deletes /var/lib/jami/.config and replaces it with a s= ymlink > > to /home/ANY-USER/.config > > * eventually, the system reboots > > * (delete-file-recursively "/var/lib/jami/.config/jami") is run. > > As "/var/lib/jami/.config" points to "/home/ANY-USER/.config", > > this means "/home/ANY-USER/.config/jami" is deleted. > > * thus, ANY-USER loses their jami configuration >=20 > The cleanup code is run as the 'jami' user, Err, the cleanup code is run from within the shepherd service, outside the fork+exec-command. The shepherd service is run _within_ the shepherd daemo= n, which runs as *root*. Only in the fork+exec-command, code is run as the 'j= ami' user; the cleanup code is run as 'root'. > so I don't think it'd be able to touch anything under /home/ANY-OTHER-USE= R/, > unless they manually loosened permissions on their home directory (shooti= ng > themselves in the foot). See my comment above. Greetings, Maxime. --=-Gs+1+lPGRZJ1CxpmLWgP Content-Type: application/pgp-signature; name="signature.asc" Content-Description: This is a digitally signed message part Content-Transfer-Encoding: 7bit -----BEGIN PGP SIGNATURE----- iI0EABYKADUWIQTB8z7iDFKP233XAR9J4+4iGRcl7gUCYH2WkBccbWF4aW1lZGV2 b3NAdGVsZW5ldC5iZQAKCRBJ4+4iGRcl7mCIAP9jTTa/0eekxqBmhORKYGL12rVg E1ZdgcCXyh36NjjXPQEA/m3pbrue/O1BDrlXO1zgfJoxFMF/6JGQcKS77cbjXwY= =1rqa -----END PGP SIGNATURE----- --=-Gs+1+lPGRZJ1CxpmLWgP--