Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1164796pxu; Mon, 23 Nov 2020 13:22:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbAGYKRuDH5Pk3ZOdi4Y0QryEOLMRaq7RY1i6E+IiLz8Qo+jFFGEd3YZlEapHl4AAFPElY X-Received: by 2002:aa7:c3cc:: with SMTP id l12mr1078372edr.304.1606166568339; Mon, 23 Nov 2020 13:22:48 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606166568; cv=none; d=google.com; s=arc-20160816; b=raYpc9LVAea+7mfAFZhWPycB5hkxpZOXT6wd/JcGm0L++SXilvGxrgC1j/jl7AyCPx CAfhDScrLmISa/GQ1f0raNeC9bvImrsVD/YUlhtpborhNtCcFIUYJAOaz4pJKIwu3ZAv 8NraclwOl7Fa9SBZBFPlq9PwQ4KD+DHyrVzbPI3XU5gazQY+3hvuK1pwv9tUt/roAgJq cHEQp3NAzRHKrO9UipoBzVPEDHcTLjwsiG+cIPzUqmgyz3YQQ67UEGWVV+GvtmNg8sib RhKpLNco2tGnoYXXoirC4nHd7iIa5XiaVZosm/yvN8ii+JCJ1QsPUFBf7FI6q/LMiv+l CFkQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=D4j9ipcYfkgbYW3IfC3r3VIMquqoN+L6cwpP+cS0BfI=; b=a6Kf2m2TMe3hZRQGmnw4Sr+CU3/p3J0RQr8eSahm21DFNdkvCkwcY5FbgjGeLh/qW9 7uiECCO8CM8902an6kXHXswe1pxTrGJJWJRSESokjPUenMXypWuWWe5a8xq4RcfeikQc wfFZSmGo/tibEOslE/ah4fthPzWyLUeqif4Q8dybrGqiFfga9yIz5hhgnnjA8RWPgECK 5wYpkJeUf9QWKCJ8uNj7v9K5ceiEc2334kt85SqXDKcaHFlnavTT6+EU/57wEIk//5Ak XAUpLd4Y0opQg53wlC+Tb3pcGllHtwoNzQ9ykIwNWscLLP+qF4SFb9ruu4R0R2++/LQm UuOQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fbC4IE3M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dm15si6580132edb.555.2020.11.23.13.22.24; Mon, 23 Nov 2020 13:22:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20161025 header.b=fbC4IE3M; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730286AbgKWVUC (ORCPT + 99 others); Mon, 23 Nov 2020 16:20:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53368 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730374AbgKWVUC (ORCPT ); Mon, 23 Nov 2020 16:20:02 -0500 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7D654C061A4F for ; Mon, 23 Nov 2020 13:20:01 -0800 (PST) Received: by mail-lf1-x142.google.com with SMTP id v14so3657904lfo.3 for ; Mon, 23 Nov 2020 13:20:01 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc:content-transfer-encoding; bh=D4j9ipcYfkgbYW3IfC3r3VIMquqoN+L6cwpP+cS0BfI=; b=fbC4IE3Ma5k4BEntewlv8v44ErN69EIIdl+LZnfvxK31fInFQJfwmWF2sg7nACKjA9 I6b6ZNKtoWl64a5fVPHAmoBsBsZ6nToMj+Obly0NP8Ez97fTOJgdkj7137/mnilNhpEh BqN/AIpYIzPy50MtZSNUjDDXyHutg+qwuyV4uGBbMumFfpKVEfROV/wlL9zO6wHExM4K moZZ3tIvtcR81IIWpQIx6JoA2Jqcw0URh9PDkR4MFHcyap+48kzcU5s1UCS3OtJ7ukUf tIaKNvwoxdNVe3mpc7VFjd4B+mci1IQXbzUjkulToK+KErFEffmZ/hPOqt64fX6Z14DN s4EQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=D4j9ipcYfkgbYW3IfC3r3VIMquqoN+L6cwpP+cS0BfI=; b=TOQb86bo7m38JH/5tVTf3kXstP0cbSIYg24DQPyx1cpH6fdlVC6mQZWEK5nXjvxEQs J0tI6GODAtdwBg4m9YKm97F/q+2vFiN3SSFEYxz3cdd8a33MOIAc6s9EEgBk+QQDVZBg PMR2KyT09i5Z+pzhSR7JiHq+L6XYlQT08Tuw/QvyfR4qFFEcFqAzyf4VE2NwzoqNI9Lk bb53z/g/4Qz/5K8QAuuCMrrck2FjnS63WR96+HGrZFWvwB7bDxDjw72sCfvKL584CZJs A/kLWNtNzS1c0c9KY8bOmldyTlauVWG0jPikrwdGdMZqY/KFcAZOBCU5BuQS4w0vGx1K EXfw== X-Gm-Message-State: AOAM532nxxq67FHNxB7v0tesY2cq15SWB/GPD1GFjDNNIPDbbX42Vnfu nf3s88R1Xd6qfHglvZAgu3/jRrktiOJmZeF+N2vQfg== X-Received: by 2002:ac2:5a49:: with SMTP id r9mr381970lfn.381.1606166399488; Mon, 23 Nov 2020 13:19:59 -0800 (PST) MIME-Version: 1.0 References: <20201112205141.775752-1-mic@digikod.net> <20201112205141.775752-8-mic@digikod.net> <1d524ea9-85eb-049c-2156-05cad6d6fcfd@digikod.net> <7831e55d-34ef-cf74-3d47-15e2e1edf96c@digikod.net> In-Reply-To: <7831e55d-34ef-cf74-3d47-15e2e1edf96c@digikod.net> From: Jann Horn Date: Mon, 23 Nov 2020 22:19:32 +0100 Message-ID: Subject: Re: [PATCH v24 07/12] landlock: Support filesystem access-control To: =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Cc: Arnd Bergmann , James Morris , "Serge E . Hallyn" , Al Viro , Andy Lutomirski , Anton Ivanov , Casey Schaufler , Jeff Dike , Jonathan Corbet , Kees Cook , Michael Kerrisk , Richard Weinberger , Shuah Khan , Vincent Dagonneau , Kernel Hardening , Linux API , linux-arch , "open list:DOCUMENTATION" , linux-fsdevel , kernel list , "open list:KERNEL SELFTEST FRAMEWORK" , linux-security-module , "the arch/x86 maintainers" , =?UTF-8?B?TWlja2HDq2wgU2FsYcO8bg==?= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Mon, Nov 23, 2020 at 10:16 PM Micka=C3=ABl Sala=C3=BCn = wrote: > On 23/11/2020 20:44, Jann Horn wrote: > > On Sat, Nov 21, 2020 at 11:06 AM Micka=C3=ABl Sala=C3=BCn wrote: > >> On 21/11/2020 08:00, Jann Horn wrote: > >>> On Thu, Nov 12, 2020 at 9:52 PM Micka=C3=ABl Sala=C3=BCn wrote: > >>>> Thanks to the Landlock objects and ruleset, it is possible to identi= fy > >>>> inodes according to a process's domain. To enable an unprivileged > >>>> process to express a file hierarchy, it first needs to open a direct= ory > >>>> (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, followi= ng > >>>> 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 iden= tify > >>>> a lot of files without tagging every inodes nor modifying the > >>>> filesystem, while still following the view and understanding the use= r > >>>> has from the filesystem. > >>>> > >>>> Add a new ARCH_EPHEMERAL_INODES for UML because it currently does no= t > >>>> 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-contro= l > >>>> which doesn't enable to restrict all file-related actions. This is = the > >>>> result of multiple discussions to minimize the code of Landlock to e= ase > >>>> review. Thanks to the Landlock design, extending this access-contro= l > >>>> without breaking user space will not be a problem. Moreover, seccom= p > >>>> filters can be used to restrict the use of syscall families which ma= y > >>>> not be currently handled by Landlock. > >>>> > >>>> Cc: Al Viro > >>>> Cc: Anton Ivanov > >>>> Cc: James Morris > >>>> Cc: Jann Horn > >>>> Cc: Jeff Dike > >>>> Cc: Kees Cook > >>>> Cc: Richard Weinberger > >>>> Cc: Serge E. Hallyn > >>>> Signed-off-by: Micka=C3=ABl Sala=C3=BCn > >>>> --- > >>>> > >>>> 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 s= ame > >>>> layer (e.g. /a allowed, /a/b denied, and /a/b/c allowed), we get > >>>> deterministic interleaved path rules. This removes an optimizatio= n > >>> > >>> 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 loo= p > >>> 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 proble= m > >>> 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 whe= re > >> exactly the access come from, we can't tell that layer 2 allowed acces= s > >> thanks to s1d3 and that its s1d2 rule was ignored. I think this behavi= or > >> 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.