From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:8:6d80::]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id KH69GQ+lfWAxqAAAgWs5BA (envelope-from ) for ; Mon, 19 Apr 2021 17:43:11 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id SGFVFQ+lfWBregAAB5/wlQ (envelope-from ) for ; Mon, 19 Apr 2021 15:43:11 +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 EF3983610C for ; Mon, 19 Apr 2021 17:43:10 +0200 (CEST) Received: from localhost ([::1]:52270 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lYW3J-0003Bo-Vj for larch@yhetil.org; Mon, 19 Apr 2021 11:43:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:57492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lYW3D-0003Bg-3s for guix-patches@gnu.org; Mon, 19 Apr 2021 11:43:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:40236) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lYW3C-0006WM-T9 for guix-patches@gnu.org; Mon, 19 Apr 2021 11:43:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1lYW3C-0001Zd-RT for guix-patches@gnu.org; Mon, 19 Apr 2021 11:43:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#47849] [PATCH 1/1] services: Add a service for the Jami daemon. Resent-From: Maxim Cournoyer Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 19 Apr 2021 15:43:02 +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: Maxime Devos Cc: 47849@debbugs.gnu.org Received: via spool by 47849-submit@debbugs.gnu.org id=B47849.16188469425974 (code B ref 47849); Mon, 19 Apr 2021 15:43:02 +0000 Received: (at 47849) by debbugs.gnu.org; 19 Apr 2021 15:42:22 +0000 Received: from localhost ([127.0.0.1]:51777 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYW2Y-0001YI-5E for submit@debbugs.gnu.org; Mon, 19 Apr 2021 11:42:22 -0400 Received: from mail-qv1-f52.google.com ([209.85.219.52]:46609) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1lYW2W-0001Y4-Ch for 47849@debbugs.gnu.org; Mon, 19 Apr 2021 11:42:21 -0400 Received: by mail-qv1-f52.google.com with SMTP id h3so16309051qve.13 for <47849@debbugs.gnu.org>; Mon, 19 Apr 2021 08:42:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=RSxKVTB4DhCWQVBqWYnlT2IXfOQlDi1uszuu4Jsd0V4=; b=BNxcQaMTZLoqqm5zJFBYRwLycxvM68gbHcUgVtN0XG9UkESYRSYw1HmeHR8k6LoAef c/aWux7Dlr1YCqYhQt+C/vsmNdpaNjtH0oA9oIjJaBB8fw9RixQ54S+9XQj9k4zuurDJ R1Snlnb9buNRSCGcnJfMaXrHTIQp6WyG69G4sASgD0253Oaf63JVl2zMSVMkb+hjIkLu d2bit7SdGBwSOZ3QDrGUaM5D0vlVAxepd9/4LI7cq4ItWvdh73FhcCpYj6BXonPYqnzW Wd/blAVBQoHiceuwhpWkfeGtPgPEj9n6Bay9FrpHlD04rR/3YEeOwtVRKUDvKN1SjjhX dknA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=RSxKVTB4DhCWQVBqWYnlT2IXfOQlDi1uszuu4Jsd0V4=; b=S4MiXJ7mp1qnXW3ZCQ0jLQih7mvtdjFhsJJl1Q6x5UqA9byc/X4v1NpQCA43c6gbrX Da2uXaCB4JQD9KfOzBbng+r1kisjRJ9IZ2ZhrtQj+zvn3Z4UTLaeWzpiVsWWXPR14vdI oDNjzASsVrw5pP1B/0Tc275hbZNVOjKoiaVO0XzFuJzTv+nXpaBVRc2r8H7UojM2CzAD d5hLe2FGFzN8VHeC7yuIB1FngkOnBrmp+JVbg2cqlt4mXS/cLY3ZZfRhqtcT/fzR17UR 3/vDfsSsh1f37jzsov8kDjuTCcJxVGL2EY/JYtDV66uJuu2jk0fXDUZZHdYWpSPPb6Ny m7pg== X-Gm-Message-State: AOAM533F0BmRhiCWUDzIzjI+pmaY+LPHN3Yz0yZJU2s4VLWx+pyK9nkw hYw4uyHnl1QnHsHMaDXu5tbgGgWUd33JFQ== X-Google-Smtp-Source: ABdhPJwpjioj8FYj4oQIDp7oQkiFYhEk5P3PEoeYG6zFk1GLT0YdQpbFWEvIq3l2xy7FiF8RuFwAIA== X-Received: by 2002:a0c:a163:: with SMTP id d90mr16310841qva.24.1618846934535; Mon, 19 Apr 2021 08:42:14 -0700 (PDT) Received: from hurd (dsl-205-151-56-5.b2b2c.ca. [205.151.56.5]) by smtp.gmail.com with ESMTPSA id g3sm1199999qtj.44.2021.04.19.08.42.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 19 Apr 2021 08:42:14 -0700 (PDT) From: Maxim Cournoyer References: <20210417200414.18050-1-maxim.cournoyer@gmail.com> <20210417200617.18182-1-maxim.cournoyer@gmail.com> <1e9354c0744afc2d5d11d3eeecaba31f62e59e65.camel@telenet.be> <87czuqiiki.fsf@gmail.com> <9fc5f3f454a77ccf2a8e09fa602755166c03abf3.camel@telenet.be> Date: Mon, 19 Apr 2021 11:42:13 -0400 In-Reply-To: <9fc5f3f454a77ccf2a8e09fa602755166c03abf3.camel@telenet.be> (Maxime Devos's message of "Mon, 19 Apr 2021 16:41:20 +0200") Message-ID: <87r1j6gu22.fsf@gmail.com> User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/27.2 (gnu/linux) MIME-Version: 1.0 Content-Type: text/plain 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=1618846991; 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=RSxKVTB4DhCWQVBqWYnlT2IXfOQlDi1uszuu4Jsd0V4=; b=ZH/dmVwVw8z6Bqb2Dlj1MdOD9f6oD8JJDtjShWp8VYCKk0srAeSAE5Sqh+T7JVZ7P1CxNC ZeRnXKsJjjVINrUF6ASfLeG4N7SkLV6ZTX1m5Wz+/C4rq30sJPTzjIJm/rC0HSraEFrXmy LFYL2Ae6aA5zOm5VhifpfE/EYNWbqLi+SmWQ4If7blxHVuktLv66QTJNiuI2CcwmQ9GhlH TEX1FjrFvXbrIZ0b0IwDQn0sonGX1W9pTDRJLPCGJtuJ2nLfBcWw+CqMWAztn0hRI/30+E DVxFz1GMhhOWgschndFcezkVsnsSUvrEkjVpFGajZ+liNnnLxZA5hYs3ocNEjg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1618846991; a=rsa-sha256; cv=none; b=rX94voJhaWcYnwGaQvsZ9f1NLXNdafyM4wfgurL3HhwwPbuWfrLkWRZYdF/rfq9Pmyqwey XMhDXBPrsbTQmFdbNbtwVD4NuML4UijTupDFFonyr2Mmi1gNMOfh3eyiCap7Bsi/AkLcKn JzG7TLsoalUz7Sb/+3C0/oEum9TGK9F7wUOS7rTW/cJ4IJU77UTEusiwbAq0+G6iagMXj7 597B/rQVVO5LEOpCuQGbvJGKXZOqNDnqu7cu2UCdAAefD46hF5npOV/a6QCd3Mzfsk4Y7O SCq3l2spssMqOrz9ucothGl+Arfa6qG7fypHOYQJAW8zfqaVcRD1iD6D4nRtYQ== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=BNxcQaMT; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (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-Spam-Score: -1.34 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gmail.com header.s=20161025 header.b=BNxcQaMT; dmarc=fail reason="SPF not aligned (relaxed)" header.from=gmail.com (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: EF3983610C X-Spam-Score: -1.34 X-Migadu-Scanner: scn0.migadu.com X-TUID: fwHsGRG8s/yy Hi Maxime, Maxime Devos writes: > Maxim Cournoyer schreef op ma 19-04-2021 om 08:07 [-0400]: >> Hi Maxime! >> >> Maxime Devos writes: >> >> > Maxim Cournoyer schreef op za 17-04-2021 om 16:06 [-0400]: >> > + [...] >> > + (delete-file-recursively "/var/lib/jami/accounts")) >> > >> > You might want to verify whether /var/lib/jami/{.cache,.config,.local/share,.local} >> > aren't symbolic links. That way, if the Jami daemon is compromised (due to buffer >> > overflow --> arbitrary code execution or something), the attacker can't trick the >> > shepherd service into deleting arbitrary directories. >> >> 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])) > > 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. Ah yes, looking the service definition it's obvious. Sorry for missing that earlier :-). > 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? Indeed! Thanks for taking the time to make it clear for me! I'll address this in a v2 patch series, hopefully resolving the issues with the daemon starting in double the first time the system is reconfigured (something to do with d-bus autospawning I think -- perhaps the D-Bus ping method is enough to spawn the process if it was not yet up and running). It'll take me some time to get to it; probably after the v1.3.0 is released. Thank you! Maxim