Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1406246imu; Wed, 28 Nov 2018 09:06:06 -0800 (PST) X-Google-Smtp-Source: AJdET5eQe0ytmKYZE8494yQhLVW3X2gN52IgvLBVgvsoHyWo7/W58gy/Nieli6VmC40PFVFnwGgY X-Received: by 2002:a62:da5a:: with SMTP id w26mr38180126pfl.106.1543424766337; Wed, 28 Nov 2018 09:06:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543424766; cv=none; d=google.com; s=arc-20160816; b=Gtw0ctuWB3zURrAWn+FCh8sLPZYiEpfd7ZUFMIhyJ++tu9SBh/cs/eAtCXQyixUp7b y49PQfhsuRF1l0ReDyWpjWPbBzPTmBSgwkFxc3/zxc5ScvD1Fox9W/LhMx/nYUUcjObp CEYwpcomQxm4HoLpoYJCz8dcvTGgK8wp1RSbaZhtkyP9uX2qu+wOvpjM2zwxrb0xwAWk dr/69lk7kmXAeRRbb8mAE7mk+VMBXTDNvGKvVVgJOSW2sesk4FfOWQEzlCXN7sdWAYWo F1jNX5B0TGbVSQlphf5/h82q8EN4dKFkO0aLuzWgU6qkrRCMD4kTKVosQ9a6Ia7ZrS9S PlEw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=8AeD7HfsaYjcTAvcp97z28hJiLq/3+J5V9S/87yy3/c=; b=OJG/dNOEBA3awXwFZAOTje1muqzsMZ5r9T+kQd7fIIk/bDXIEqoMr/fIllDrFdvhtL rqR7i41V8z8rtoMSXY5IG0i9A8M3l1ZH0Jbh1wkpWGKLgxbQmfSDBtvjZjXA8cq+BYSu +Qy2g0EWdvghwOCxmrxD3u4H4j0r5AlDK52K2RvSYrtroWfE0If/iXF6l3zky5mXuC4H 10Yclfd9MBWrKOyCNmtvHe6EVy0Y48VG3hVU7wpB5NUOA+Emc6TOw2SJEXlRHG71E/wz q0mvlQ3ezLRJZSy//5xUtZsa1fTfsmnB14QBM5gACy52u256lSQRLPLGQ77YSnuScltT Dk5w== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id p8si7696122plk.263.2018.11.28.09.05.42; Wed, 28 Nov 2018 09:06:06 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729093AbeK2EF0 (ORCPT + 99 others); Wed, 28 Nov 2018 23:05:26 -0500 Received: from mx1.redhat.com ([209.132.183.28]:49212 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728807AbeK2EFZ (ORCPT ); Wed, 28 Nov 2018 23:05:25 -0500 Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B946430832C1; Wed, 28 Nov 2018 17:03:05 +0000 (UTC) Received: from horse.redhat.com (unknown [10.18.25.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 492307C281; Wed, 28 Nov 2018 17:03:03 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id C61052208FC; Wed, 28 Nov 2018 12:03:02 -0500 (EST) Date: Wed, 28 Nov 2018 12:03:02 -0500 From: Vivek Goyal To: Miklos Szeredi Cc: Stephen Smalley , 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 Subject: Re: overlayfs access checks on underlying layers Message-ID: <20181128170302.GA12405@redhat.com> References: <20181127210542.GA2599@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Wed, 28 Nov 2018 17:03:05 +0000 (UTC) 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 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. Thanks Vivek