linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jann Horn <jannh@google.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: "Arnd Bergmann" <arnd@arndb.de>,
	"James Morris" <jmorris@namei.org>,
	"Serge E . Hallyn" <serge@hallyn.com>,
	"Al Viro" <viro@zeniv.linux.org.uk>,
	"Andy Lutomirski" <luto@amacapital.net>,
	"Anton Ivanov" <anton.ivanov@cambridgegreys.com>,
	"Casey Schaufler" <casey@schaufler-ca.com>,
	"Jeff Dike" <jdike@addtoit.com>,
	"Jonathan Corbet" <corbet@lwn.net>,
	"Kees Cook" <keescook@chromium.org>,
	"Michael Kerrisk" <mtk.manpages@gmail.com>,
	"Richard Weinberger" <richard@nod.at>,
	"Shuah Khan" <shuah@kernel.org>,
	"Vincent Dagonneau" <vincent.dagonneau@ssi.gouv.fr>,
	"Kernel Hardening" <kernel-hardening@lists.openwall.com>,
	"Linux API" <linux-api@vger.kernel.org>,
	linux-arch <linux-arch@vger.kernel.org>,
	"open list:DOCUMENTATION" <linux-doc@vger.kernel.org>,
	linux-fsdevel <linux-fsdevel@vger.kernel.org>,
	"kernel list" <linux-kernel@vger.kernel.org>,
	"open list:KERNEL SELFTEST FRAMEWORK"
	<linux-kselftest@vger.kernel.org>,
	linux-security-module <linux-security-module@vger.kernel.org>,
	"the arch/x86 maintainers" <x86@kernel.org>,
	"Mickaël Salaün" <mic@linux.microsoft.com>
Subject: Re: [PATCH v24 07/12] landlock: Support filesystem access-control
Date: Mon, 23 Nov 2020 22:19:32 +0100	[thread overview]
Message-ID: <CAG48ez2V-eSH2+HL9zrYYD4QMpP4a5y8=mTQtk20PB0wUz_4Tw@mail.gmail.com> (raw)
In-Reply-To: <7831e55d-34ef-cf74-3d47-15e2e1edf96c@digikod.net>

On Mon, Nov 23, 2020 at 10:16 PM Mickaël Salaün <mic@digikod.net> wrote:
> On 23/11/2020 20:44, Jann Horn wrote:
> > On Sat, Nov 21, 2020 at 11:06 AM Mickaël Salaün <mic@digikod.net> wrote:
> >> On 21/11/2020 08:00, Jann Horn wrote:
> >>> On Thu, Nov 12, 2020 at 9:52 PM Mickaël Salaün <mic@digikod.net> wrote:
> >>>> Thanks to the Landlock objects and ruleset, it is possible to identify
> >>>> inodes according to a process's domain.  To enable an unprivileged
> >>>> process to express a file hierarchy, it first needs to open a directory
> >>>> (or a file) and pass this file descriptor to the kernel through
> >>>> landlock_add_rule(2).  When checking if a file access request is
> >>>> allowed, we walk from the requested dentry to the real root, following
> >>>> the different mount layers.  The access to each "tagged" inodes are
> >>>> collected according to their rule layer level, and ANDed to create
> >>>> access to the requested file hierarchy.  This makes possible to identify
> >>>> a lot of files without tagging every inodes nor modifying the
> >>>> filesystem, while still following the view and understanding the user
> >>>> has from the filesystem.
> >>>>
> >>>> Add a new ARCH_EPHEMERAL_INODES for UML because it currently does not
> >>>> keep the same struct inodes for the same inodes whereas these inodes are
> >>>> in use.
> >>>>
> >>>> This commit adds a minimal set of supported filesystem access-control
> >>>> which doesn't enable to restrict all file-related actions.  This is the
> >>>> result of multiple discussions to minimize the code of Landlock to ease
> >>>> review.  Thanks to the Landlock design, extending this access-control
> >>>> without breaking user space will not be a problem.  Moreover, seccomp
> >>>> filters can be used to restrict the use of syscall families which may
> >>>> not be currently handled by Landlock.
> >>>>
> >>>> Cc: Al Viro <viro@zeniv.linux.org.uk>
> >>>> Cc: Anton Ivanov <anton.ivanov@cambridgegreys.com>
> >>>> Cc: James Morris <jmorris@namei.org>
> >>>> Cc: Jann Horn <jannh@google.com>
> >>>> Cc: Jeff Dike <jdike@addtoit.com>
> >>>> Cc: Kees Cook <keescook@chromium.org>
> >>>> Cc: Richard Weinberger <richard@nod.at>
> >>>> Cc: Serge E. Hallyn <serge@hallyn.com>
> >>>> Signed-off-by: Mickaël Salaün <mic@linux.microsoft.com>
> >>>> ---
> >>>>
> >>>> Changes since v23:
> >>>> * Enforce deterministic interleaved path rules.  To have consistent
> >>>>   layered rules, granting access to a path implies that all accesses
> >>>>   tied to inodes, from the requested file to the real root, must be
> >>>>   checked.  Otherwise, stacked rules may result to overzealous
> >>>>   restrictions.  By excluding the ability to add exceptions in the same
> >>>>   layer (e.g. /a allowed, /a/b denied, and /a/b/c allowed), we get
> >>>>   deterministic interleaved path rules.  This removes an optimization
> >>>
> >>> I don't understand the "deterministic interleaved path rules" part.
> >>
> >> I explain bellow.
> >>
> >>>
> >>>
> >>> What if I have a policy like this?
> >>>
> >>> /home/user READ
> >>> /home/user/Downloads READ+WRITE
> >>>
> >>> That's a reasonable policy, right?
> >>
> >> Definitely, I forgot this, thanks for the outside perspective!
> >>
> >>>
> >>> If I then try to open /home/user/Downloads/foo in WRITE mode, the loop
> >>> will first check against the READ+WRITE rule for /home/user, that
> >>> check will pass, and then it will check against the READ rule for /,
> >>> which will deny the access, right? That seems bad.
> >>
> >> Yes that was the intent.
> >>
> >>>
> >>>
> >>> The v22 code ensured that for each layer, the most specific rule (the
> >>> first we encounter on the walk) always wins, right? What's the problem
> >>> with that?
> >>
> >> This can be explained with the interleaved_masked_accesses test:
> >> https://github.com/landlock-lsm/linux/blob/landlock-v24/tools/testing/selftests/landlock/fs_test.c#L647
> >>
> >> In this case there is 4 stacked layers:
> >> layer 1: allows s1d1/s1d2/s1d3/file1
> >> layer 2: allows s1d1/s1d2/s1d3
> >>          denies s1d1/s1d2
> >> layer 3: allows s1d1
> >> layer 4: allows s1d1/s1d2
> >>
> >> In the v23, access to file1 would be allowed until layer 3, but layer 4
> >> would merge a new rule for the s1d2 inode. Because we don't record where
> >> exactly the access come from, we can't tell that layer 2 allowed access
> >> thanks to s1d3 and that its s1d2 rule was ignored. I think this behavior
> >> doesn't make sense from the user point of view.
> >
> > Aah, I think I'm starting to understand the issue now. Basically, with
> > the current UAPI, the semantics have to be "an access is permitted if,
> > for each policy layer, at least one rule encountered on the pathwalk
> > permits the access; rules that deny the access are irrelevant". And if
> > it turns out that someone needs to be able to deny access to specific
> > inodes, we'll have to extend struct landlock_path_beneath_attr.
>
> Right, I'll add this to the documentation (aligned with the new
> implementation).
>
> >
> > That reminds me... if we do need to make such a change in the future,
> > it would be easier in terms of UAPI compatibility if
> > landlock_add_rule() used copy_struct_from_user(), which is designed to
> > create backwards and forwards compatibility with other version of UAPI
> > headers. So adding that now might save us some headaches later.
>
> I used copy_struct_from_user() before v21, but Arnd wasn't a fan of
> having type and size arguments, so we simplified the UAPI in the v21 by
> removing the size argument. The type argument is enough to extend the
> structure, but indeed, we lose the forward compatibility. Relying on one
> syscall per rule type seems too much, though.

You have a point there, I guess having a type argument is enough. (And
if userspace tries to load a ruleset with "deny" rules that isn't
supported by the current kernel, userspace will have to deal with that
in some way anyway.)

So thinking about it more, I guess the current version is probably
actually fine, too.

  reply	other threads:[~2020-11-23 21:20 UTC|newest]

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-11-12 20:51 [PATCH v24 00/12] Landlock LSM Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 01/12] landlock: Add object management Mickaël Salaün
2020-11-21  7:00   ` Jann Horn
2020-11-21 10:11     ` Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 02/12] landlock: Add ruleset and domain management Mickaël Salaün
2020-11-20  1:52   ` James Morris
2020-11-21  7:00   ` Jann Horn
2020-11-21  9:45     ` Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 03/12] landlock: Set up the security framework and manage credentials Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 04/12] landlock: Add ptrace restrictions Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 05/12] LSM: Infrastructure management of the superblock Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 06/12] fs,security: Add sb_delete hook Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 07/12] landlock: Support filesystem access-control Mickaël Salaün
2020-11-21  7:00   ` Jann Horn
2020-11-21 10:06     ` Mickaël Salaün
2020-11-23 19:44       ` Jann Horn
2020-11-23 21:16         ` Mickaël Salaün
2020-11-23 21:19           ` Jann Horn [this message]
2020-11-12 20:51 ` [PATCH v24 08/12] landlock: Add syscall implementations Mickaël Salaün
2020-11-21  7:00   ` Jann Horn
2020-11-12 20:51 ` [PATCH v24 09/12] arch: Wire up Landlock syscalls Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 10/12] selftests/landlock: Add user space tests Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 11/12] samples/landlock: Add a sandbox manager example Mickaël Salaün
2020-11-12 20:51 ` [PATCH v24 12/12] landlock: Add user and kernel documentation Mickaël Salaün
2020-11-21  7:00   ` Jann Horn
2020-11-24  2:38     ` James Morris
2020-11-17  5:37 ` [PATCH v24 00/12] Landlock LSM James Morris

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='CAG48ez2V-eSH2+HL9zrYYD4QMpP4a5y8=mTQtk20PB0wUz_4Tw@mail.gmail.com' \
    --to=jannh@google.com \
    --cc=anton.ivanov@cambridgegreys.com \
    --cc=arnd@arndb.de \
    --cc=casey@schaufler-ca.com \
    --cc=corbet@lwn.net \
    --cc=jdike@addtoit.com \
    --cc=jmorris@namei.org \
    --cc=keescook@chromium.org \
    --cc=kernel-hardening@lists.openwall.com \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-arch@vger.kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fsdevel@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-kselftest@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=luto@amacapital.net \
    --cc=mic@digikod.net \
    --cc=mic@linux.microsoft.com \
    --cc=mtk.manpages@gmail.com \
    --cc=richard@nod.at \
    --cc=serge@hallyn.com \
    --cc=shuah@kernel.org \
    --cc=vincent.dagonneau@ssi.gouv.fr \
    --cc=viro@zeniv.linux.org.uk \
    --cc=x86@kernel.org \
    /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).