Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1628267imu; Wed, 28 Nov 2018 12:26:18 -0800 (PST) X-Google-Smtp-Source: AFSGD/WnIuaewLOAdq2neX/BByZ7IEJ8LpBx7yJmS4rCVzg4R3S4djW1xju265PV9nmziV/EyTJh X-Received: by 2002:a65:6392:: with SMTP id h18mr35017596pgv.107.1543436778210; Wed, 28 Nov 2018 12:26:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543436778; cv=none; d=google.com; s=arc-20160816; b=VqtclAEIFV4GEeUG/b0JjVEUp7zjHuMJKRkizkvgFvXvBujKMUZ4Z8oVkf2GlHWur7 q1+ULSL45MO+hSJvPDm+Yy9j7RwvCqL2XhxUorArnkpqvFZIXV1Tes/7C/GFydcR1XQe jZckR87zALo+f878TRJa3eW+sbD3a5AmU4/eu88an7bPrp6yeaV5gV8s106wldgjvzy8 3JsKX2SMl57XmVEB/ndq7DFyCYEgonWbjxn1V0In3Rn86wDskGZeris3JTailEpnr2oe zsLGpwBmD0E99VIfcpIlG/rUYkMAVeQsYJvNaJzuYbDPmTaMbV6TgYuNKh4O03J5tWG5 9xtw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=+wtvzNXNsghsUV9rhnBRk80A7osfukfxtyy6m+YtjK0=; b=tOyhMtjVaLpcT6I/QWltn2dx3jKwMsLDx9LEePxOwbmBvjzcG1B/1ODBqFg7o3ERBO HzEKawvvKP/zdkRvcUzo8gYEVIMa7HOckyQNfFo5QNR3Ruep8g5TzUqZ8T6anLGIt8ID A+mJxa4GOSr5lljQXAzNYwyAExkF8R4aWCDpe7hrTXmhkI657SdjamLA6UK8XjF4ShO7 HfEhUc46N6xt5uLvYm6sEpaH105lLywB3PuvOQEoMUMJGdw2RKeNtTl9sYBWOHOeS3Q4 TuOvWBiEFT3KfShnarB9OrEeIYtBG/e/M5rO+dSXOUsrQfJEj3Gyc3LAakWl4cq/YkVX wq4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=bYxqmhIr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id x9si8169924pll.131.2018.11.28.12.25.59; Wed, 28 Nov 2018 12:26:18 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=bYxqmhIr; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729158AbeK2H2C (ORCPT + 99 others); Thu, 29 Nov 2018 02:28:02 -0500 Received: from mail-it1-f196.google.com ([209.85.166.196]:54872 "EHLO mail-it1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728855AbeK2H2B (ORCPT ); Thu, 29 Nov 2018 02:28:01 -0500 Received: by mail-it1-f196.google.com with SMTP id m123-v6so6537380ita.4 for ; Wed, 28 Nov 2018 12:25:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=szeredi.hu; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=+wtvzNXNsghsUV9rhnBRk80A7osfukfxtyy6m+YtjK0=; b=bYxqmhIrZ3ohXgLbEGMCoLlKu248H0qJ2f7404WgbsPovYALNjtzCzTiHy5RW03Uro BkDHSHkO4mSH8Gb/exuoSS3adjeXM13myQ7ajcJII4XWnWDKBbHbOGWC7QCyVktTs0TG DMnZzXNMVZQHFuipaaoSwzuWNjm/2Jh9EEbj4= 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; bh=+wtvzNXNsghsUV9rhnBRk80A7osfukfxtyy6m+YtjK0=; b=WNS4F4x+B63Weo3Mw/Y1iNWRpsYI0V0DLHHiSFEaT341dbAP99f1vp7Gfi9G73Kzxr yRQEUgBInVDGxtEk7WVP3kLTPXB49FXXcmqGD0b25ruSKiz5E1T3jtQJRORdGyyHJoHk 0nn+n7PR/FWYLfmWwd/eFNti8R8nLAKQUcvtaBt/sU01BMCmS2Zzcjjvk3FHAVItxwtX f8TWoNLaXvZOq5TSd4OO/8h19adpdcK8zC41n91w27i+iIQvqvbZVyov62NhiE7RhU1Y U+rdANl+SYeyRf+vA4Kwciun6PU645JmVJ1BKV03XC+oyV9ue5sVZxDrBge4GcJ3k2Fm D6hg== X-Gm-Message-State: AA+aEWaE8MyWlG7JFV/QvmF5R/CaOPmNcTbKykdkGeG8WrUzXlCu0iGI 4qV3IssGjeiXABLGU8Lty3uuAAzXpL4zuOp29VljUw== X-Received: by 2002:a24:710:: with SMTP id f16mr3869840itf.121.1543436709386; Wed, 28 Nov 2018 12:25:09 -0800 (PST) MIME-Version: 1.0 References: <20181127210542.GA2599@redhat.com> <20181128170302.GA12405@redhat.com> <377b7d4f-eb1d-c281-5c67-8ab6de77c881@tycho.nsa.gov> In-Reply-To: <377b7d4f-eb1d-c281-5c67-8ab6de77c881@tycho.nsa.gov> From: Miklos Szeredi Date: Wed, 28 Nov 2018 21:24:57 +0100 Message-ID: Subject: Re: overlayfs access checks on underlying layers To: Stephen Smalley Cc: Vivek Goyal , Ondrej Mosnacek , "J. Bruce Fields" , Mark Salyzyn , Paul Moore , linux-kernel@vger.kernel.org, overlayfs , linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org, Daniel J Walsh Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Nov 28, 2018 at 8:32 PM Stephen Smalley wrote: > > On 11/28/18 12:03 PM, Vivek Goyal wrote: > > On Wed, Nov 28, 2018 at 11:00:09AM +0100, Miklos Szeredi wrote: > >> On Tue, Nov 27, 2018 at 10:05 PM Vivek Goyal wrote: > >>> > >>> On Tue, Nov 27, 2018 at 08:58:06PM +0100, Miklos Szeredi wrote: > >>>> [resending with fixed email address for Paul Moore] > >>>> > >>>> Moving discussion from github[1] to here. > >>>> > >>>> To summarize: commit 007ea44892e6 ("ovl: relax permission checking on > >>>> underlying layers") was added in 4.20-rc1 to make overlayfs access > >>>> checks on underlying "real" filesystems more consistent. The > >>>> discussion leading up to this commit can be found at [2]. The commit > >>>> broke some selinux-testsuite cases, possibly indicating a security > >>>> hole opened by this commit. > >>>> > >>>> The model this patch tries to follow is that if "cp --preserve=all" > >>>> was allowed to the mounter from underlying layer to the overlay layer, > >>>> then operation is allowed. That means even if mounter's creds doesn't > >>>> provide permission to for example execute underying file X, if > >>>> mounter's creds provide sufficient permission to perform "cp > >>>> --preserve=all X Y" and original creds allow execute on Y, then the > >>>> operation is allowed. This provides consistency in the face of > >>>> copy-ups. Consistency is only provided in sane setups, where mounter > >>>> has sufficient privileges to access both the lower and upper layers. > >>> > >>> [cc daniel walsh] > >>> > >>> I think current selinux testsuite tests are written keeping these > >>> rules in mind. > >>> > >>> 1. Check overlay inode creds in the context of task and underlying > >>> inode creds (lower/upper), in the context of mounter. > >>> > >>> 2. For a lower inode, if said file is being copied up, then only > >>> check MAY_READ on lower. This is equivalent to mounter creating > >>> a copy of file and providing caller access to it (context mount). > >>> > >>> For the case of special devices, we do not copy up these. So should > >>> we continue to do check on lower inode in the context of mounter > >>> (instead of not doing any check on lower at all). > >> > >> Hmm, I'm trying to understand the logic... If we follow the "cp > >> --preserve=all" thing, than mounter needs to have CREATE permission > >> for the special file, not READ or WRITE. Does that make sense? Would > >> that help with the context= mount use case? > > > > Ok. If we follow "cp --preserve=all" methodology, then checking for > > mounter CREATE permission on upper for special files makes sense. Or > > change logic to copy up this special file during open. I am assuming > > we don't copy up special file during open as it is not necessary > > for things to work but copying up will work as well? > > > > So rules will become. > > > > - Two levels of checks. > > - For lower level inode, check MAY_READ for regular files. (including > > exec). > > - For special files, only make sure mounter can CREATE object in upper. > > > > - What about checks on files on upper/. As of now we seem to check > > access in mounter's context if it is regular file. Skip the checks > > completely for special files and for executables. > > > > While non-context mount should still be ok, but this means lot of > > privilige granting to unprivileged process using context mounts. So > > unprivileged process which could not open a device/socket/fifo for > > read/write on host fs, can open it for those operations for context > > mounts. > > > > IOW, for context mount case, an unprivileged user will gain lot of > > privileges. But that seems to be the point of context mount anyway > > on regular disks. If a disk is mounted using context mount option, > > then all real labels are ignored and all access checking happens > > using context label. We are doing similar thing. With one step extra > > and that is making sure if mounter itself can not do certain operation > > on host, that will still be denied. > > > > This probably means that context= mounts should be used very carefully. > > It will grant lot of priviliges to the process (and allow operations > > which process could not do on host without overlayfs mount). > > > > Case of device file still baffels me though. We don't do any mounter's > > checks on device files. So if a device file is on upper which mounter > > can't open for read but mounter is still granting priviliges to client > > to open that device file. That's unintutive to me and seems counter > > to the principle of that mounter can't give more priviliges than what > > it itself can't do on host. > > > > Dan, stephen, paul moore, does this sound ok to you folks from selinux > > point of view. > > It seems wrong to check CREATE when no file is being created, and doing > so could lead to over-privileging of the mounter context, requiring one > to allow a mounter context to create device nodes just to allow a client > task context to read/write via already existing device nodes through an > overlay. Point taken. > > Checking READ but not EXECUTE upon an execute check could permit a > mounter to execute unauthorized code, if it can context mount from a > readable-but-not-executable context to an executable context. > > Note btw that cp --preserve=all doesn't quite operate as expected if > dealing with a context mount. You can't preserve the original security > context if copying to a context mount unless the two contexts happen to > already match. So I'm not sure how that model applies in the case of a > context mount. > > Does the breaking commit (007ea44892e6) fix a real bug affecting users? > If not, I'd recommend just reverting it. That is certainly an option, but... this is all about context= mounts, right? Which allows mounter to override MAC checks under the new mount? On any mount, not just overlay, right? So why is overlay special? I'd just like to see proper justification for why we should be doing those checks on underlying layer that simply don't belong there, IMO. I'm sure you know better than I that it's not just about real bugs affecting users, it's about having a clear, well defined model to base the design on. And by reverting the breaking commit, I don't see us getting closer to that. Thanks, Miklos