linux-security-module.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Günther Noack" <gnoack3000@gmail.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: Tyler Hicks <code@tyhicks.com>,
	Christian Brauner <brauner@kernel.org>,
	landlock@lists.linux.dev,
	linux-security-module <linux-security-module@vger.kernel.org>,
	Linux-Fsdevel <linux-fsdevel@vger.kernel.org>,
	Al Viro <viro@zeniv.linux.org.uk>
Subject: Re: Does Landlock not work with eCryptfs?
Date: Mon, 27 Mar 2023 23:01:13 +0200	[thread overview]
Message-ID: <20230327.bddbc828c0ec@gnoack.org> (raw)
In-Reply-To: <fbaa6222-255d-57fa-c2fe-f69752a4cb35@digikod.net>

Hello!

On Sun, Mar 26, 2023 at 11:19:19PM +0200, Mickaël Salaün wrote:
> On 24/03/2023 23:53, Tyler Hicks wrote:
> > On 2023-03-21 19:16:28, Mickaël Salaün wrote:
> > > If Tyler is OK with the proposed solutions, I'll get a closer look at it in
> > > a few months. If anyone is interested to work on that, I'd be happy to
> > > review and test (the Landlock part).
> > 
> > I am alright with using the mounter creds but eCryptfs is typically
> > mounted as root using a PAM module so the mounter is typically going to
> > be more privileged than the user accessing the eCryptfs mount (in the
> > common case of an encrypted home directory).
> > 
> > But, as Christian points out, I think it might be better to make
> > Landlock refuse to work with eCryptfs. Would you be at ease with that
> > decision if we marked eCryptfs as deprecated with a planned removal
> > date?
> 
> The only way to make Landlock "refuse" to work with eCryptfs would be to add
> exceptions according to the underlying filesystem when creating rules.
> Furthermore, to be consistent, this would need to be backported. I don't
> want to go in such direction to fix an eCryptfs issue.

Here is an example where the Landlock LSM can't detect eCryptfs:

  mkdir -p /foo/bar/baz /foo/secret
  landlock-restrict -ro / -rw /foo/bar -- /bin/bash
  
  # finally, in a different terminal:
  mount.ecryptfs /foo/secret /foo/bar/baz

The shell is supposed to have access to /foo/bar and everything below
it, but at the time of creating the Landlock ruleset, it can't tell
yet that this directory will contain an eCryptfs mount later.

Admittedly, the example is obscure, but it's strictly speaking
supposed to work according to the Landlock documentation.  (Only the
landlocked process can't use mount(2) any more, but other processes
still can.)

Note on the side: Even when mount.ecryptfs happens before the Landlock
restriction, the Landlock LSM would have to traverse the existing
mounts to see if there is an eCryptfs mount *below* /foo/bar.

> Doing nothing would go against the principle of least astonishment because
> of unexpected and inconsistent behavior when using Landlock with eCryptfs.
> Indeed, Landlock users (e.g. app developers) may not know how, where, and on
> which kernel their sandboxed applications will run. This means that at best,
> developers will (potentially wrongly) check if eCryptfs is available/used
> and then disable sandboxing, and at worse the (opportunistically) sandboxed
> apps will break (because of denied access). In any case, it goes against
> user's interests.

I agree, I also believe that a kernel-side fix is needed.

I don't think this is feasible to do in a good way in userspace, even
if we want to resort to "falling back to doing nothing" in best effort
mode if eCryptfs file hierarchies are affected.

I have pondered these userspace approaches how to detect eCryptfs, but
they are both lacking:

* Looking for eCryptfs in /proc/mounts might not work
  if we are layering multiple Landlock rulesets.

* stat(2) also does not give away whether a file is on eCryptfs
  (the device number is just a generic kernel internal one)

Finally, it all falls apart anyway if we want to support the case
where eCryptfs is mounted after enabling the sandbox.  (Obscure, but
possible.)

> Even if eCryptfs is marked as deprecated, it will be available for years (a
> lot for LTS) and (legitimate) bug reports will keep coming.
> 
> Instead, I'd like to fix the eCryptfs inconsistent behavior (highlighted by
> Landlock and other LSMs). I think it's worth trying the first proposed
> solution, which might not be too difficult to implement, and will get
> eCryptfs closer to the overlayfs semantic.

+1. As you also said: I think it's important to fix it in the LTS
releases, so that we can tell people to use Landlock without having to
think about these corner cases.

–Günther

      reply	other threads:[~2023-03-27 21:01 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <20230319.2139b35f996f@gnoack.org>
2023-03-19 21:00 ` Does Landlock not work with eCryptfs? Mickaël Salaün
2023-03-20 17:15   ` Günther Noack
2023-03-20 17:21     ` Mickaël Salaün
2023-03-21 16:36       ` Mickaël Salaün
2023-03-21 17:24         ` Christian Brauner
2023-03-21 18:16           ` Mickaël Salaün
2023-03-23 17:05             ` Günther Noack
2023-03-24 22:45               ` Tyler Hicks (Microsoft)
2023-03-24 22:53             ` Tyler Hicks
2023-03-26 21:19               ` Mickaël Salaün
2023-03-27 21:01                 ` Günther Noack [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230327.bddbc828c0ec@gnoack.org \
    --to=gnoack3000@gmail.com \
    --cc=brauner@kernel.org \
    --cc=code@tyhicks.com \
    --cc=landlock@lists.linux.dev \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=viro@zeniv.linux.org.uk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).