Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8365905imu; Tue, 4 Dec 2018 07:18:12 -0800 (PST) X-Google-Smtp-Source: AFSGD/V9WFbr+sMKZ4BxKBVMnEWHizd5R9Mll+7EmfN9MesT4Zc1lkDliiz6WjJbWuQCTbVPRaAU X-Received: by 2002:a63:5346:: with SMTP id t6mr17490591pgl.40.1543936692015; Tue, 04 Dec 2018 07:18:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543936691; cv=none; d=google.com; s=arc-20160816; b=nRgv9GZKdpP9lybhSJACq5S6bzmEbgdM4ZTXHhWffVVQoje3KQfY6zGxcS8+ek6XlL ig3xWGPmldGvqpzGHOEYed9tUtgW72Rsm0q+nJhlaXTk2xXllGcuzoAgDsLtVYSdRSIP LvQp67VOW5XDlNbjgQ5c5HWueVzJcCl+fqsxSD73D5NUAdkG7EBMMHe9RPvPKS4BuFbd 0KQYwifaJRtW4lf4EKh1TGUW45olKR9rA4tF36fsIV8nlelakvp60IbsyW/ykxtYHLh4 Nh8pcnvF295k5LzbGUBms/yfLRqk7gX33dOKSlRXIeuI6mdS4YMffKTlO/gH+7jB6CU4 FtlQ== 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=2HqNc64koNrE5aBwgFQJ8Hcc1NcRCC6tOE/0YAlZpyk=; b=ghzEGu5dZFPALa8v+ghlb6lUehlb1fJKWFbuy1hyeyPkOItv6IIWd0rHaoU70YVBOC hoBQHglPTsN9Zo8nriA9/3dTGXjXqQg2NsCov6MGrSWnSRha5X0RcbZQHpbmRCI8g+kh /5hecMPxkUBMvtkWpwbd/Of37iUVP9lIJBSsRUqcY9gU9iJjlyggsXDXtmedowxfHyMq mEl3PAUJbsU83tLCxJxT0+UTPHqxFQ/mTltFA1hSFZeoDtE1BfTk089N98KTdXQMNRm2 OpJoRA5WEWSrmuZK1hWC2EFKYfCenheAL5Ph95UH/MlGxtdGOR6EttPFNhpmSbBf2U3l 4h2Q== 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 q24si18157835pls.325.2018.12.04.07.17.45; Tue, 04 Dec 2018 07:18:11 -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 S1726618AbeLDPPv (ORCPT + 99 others); Tue, 4 Dec 2018 10:15:51 -0500 Received: from mx1.redhat.com ([209.132.183.28]:28292 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725955AbeLDPPv (ORCPT ); Tue, 4 Dec 2018 10:15:51 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2B118308ED62; Tue, 4 Dec 2018 15:15:50 +0000 (UTC) Received: from horse.redhat.com (unknown [10.18.25.234]) by smtp.corp.redhat.com (Postfix) with ESMTP id 8B93D60920; Tue, 4 Dec 2018 15:15:49 +0000 (UTC) Received: by horse.redhat.com (Postfix, from userid 10451) id 18F8A2208FC; Tue, 4 Dec 2018 10:15:49 -0500 (EST) Date: Tue, 4 Dec 2018 10:15:49 -0500 From: Vivek Goyal To: Stephen Smalley Cc: Miklos Szeredi , 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: <20181204151549.GA21509@redhat.com> References: <377b7d4f-eb1d-c281-5c67-8ab6de77c881@tycho.nsa.gov> <26bce3be-49c2-cdd8-af03-1a78d0f268ae@tycho.nsa.gov> <6b125e8e-413f-f8e6-c7ae-50f7235c8960@tycho.nsa.gov> <4c20a261-5ce1-f0a2-8d40-c6032a023216@tycho.nsa.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <4c20a261-5ce1-f0a2-8d40-c6032a023216@tycho.nsa.gov> User-Agent: Mutt/1.9.1 (2017-09-22) X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.44]); Tue, 04 Dec 2018 15:15:50 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Dec 04, 2018 at 09:30:53AM -0500, Stephen Smalley wrote: > On 12/4/18 8:32 AM, Miklos Szeredi wrote: > > On Thu, Nov 29, 2018 at 10:16 PM Stephen Smalley wrote: > > > > > > On 11/29/18 4:03 PM, Stephen Smalley wrote: > > > > On 11/29/18 2:47 PM, Miklos Szeredi wrote: > > > > > On Thu, Nov 29, 2018 at 5:14 PM Stephen Smalley > > > > > wrote: > > > > > > > > > > > Possibly I misunderstood you, but I don't think we want to copy-up on > > > > > > permission denial, as that would still allow the mounter to read/write > > > > > > special files or execute regular files to which it would normally be > > > > > > denied access, because the copy would inherit the context specified by > > > > > > the mounter in the context mount case. It still represents an > > > > > > escalation of privilege for the mounter. In contrast, the copy-up on > > > > > > write behavior does not allow the mounter to do anything it could not do > > > > > > already (i.e. read from the lower, write to the upper). > > > > > > > > > > Let's get this straight: when file is copied up, it inherits label > > > > > from context=, not from label of lower file? > > > > > > > > That's correct. The overlay inodes are all assigned the label from the > > > > context= mount option, and so are any upper inodes created through the > > > > overlay. At least that's my understanding of how it is supposed to > > > > work. The original use case was for containers with the lower dir > > > > labeled with a context that is read-only to the container context and > > > > using a context that is writable by the container context for the > > > > context= mount. > > > > > > > > > Next question: permission to change metadata is tied to permission to > > > > > open? Is it possible that open is denied, but metadata can be > > > > > changed? > > > > > > > > There is no metadata change occurring here. The overlay, upper, and > > > > lower inodes all keep their labels intact for their lifetime (both > > > > overlay and upper always have the context= label; upper has whatever its > > > ^^lower^^ > > > > > > > original label was), unless explicitly relabeled by some process. And > > > > when viewed through the overlay, the file always has the label specified > > > > via context=, even before the copy-up. > > > > Okay. > > > > > > > > > > > DAC model allows this: metadata change is tied to ownership, not mode > > > > > bits. And different capability flag. > > > > > > > > > > If the same is true for MAC, then the pre-v4.20-rc1 is already > > > > > susceptible to the privilege escalation you describe, right? > > > > > > > > Actually, I guess there wouldn't be a privilege escalation if you > > > > checked the mounter's ability to create the new file upon copy-up, and > > > > checked the mounter's access to the upper inode label upon the > > > > subsequent read, write, or execute access. Then we'd typically block > > > > the ability to create the device file and we'd block the ability to > > > > execute files with the label from context=. > > > > > > > > But copy-up of special files seems undesirable for other reasons (e.g. > > > > requiring mounters to be allowed to create device nodes just to permit > > > > client's to read/write them, possible implications for nodev/noexec, > > > > implications for socket and fifo files). > > > > I think you missed my point: opening a device file or executing an > > executable wouldn't normally require copy-up. If > > > > - permission is granted on overlay to task, and > > - permission is granted on lower layer to mounter, > > > > then copy-up wouldn't be performed. > > > > My proposed sequence would be > > > > a) check task's creds against overlay inode, fail -> return fail, otherwise: > > b) check mounter's creds against lower inode, success -> return > > success, otherwise: > > c) copy up inode, fail -> return fail, otherwise > > d) check mounter's creds against upper inode, return result. > > > > So, unlike write access to regular files, write access to special > > files don't necessarily result in copy-up. > > > > You say this is an escalation of privilege, but I don't get it how. > > As DWalsh points out downthread, if mounter cannot create device > > files, then the copy-up will simply fail. If mounter can create > > device files, then this is not an escalation of privilege for the > > mounter. > > Yes, in that case there isn't an escalation of privilege for the mounter (I > acknowledged that above). I'm still not sure copy-up of special files is a > good idea though: > > - In the case of device files, there is the potential for mischief by the > client task in misusing the mounter's privileges to gain access to otherwise > unusable device node (nodev lower vs upper?), I was thinking about it as well. But client can always bypass permissions of lower device inode by first removing device file and then by doing a mknod. And that will be equivalent of copy up. IOW, IIUC, we do not deny mknod to client and that always creates a way for it to write to device file (and it does not matter what are permissions on lower?) > - In the case of sockets or fifos, what useful result do you get from a > copy-up? Accessing the copy isn't going to yield the same result as > accessing the original. sockets and fifos use overlay inode number (and not lower/upper inode number). So even if we create a copy things continue to work. Copying up will make sense upon owner or permission change to determine who can open socket/fifo in future? Thanks Vivek