Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7578321imu; Mon, 3 Dec 2018 15:29:09 -0800 (PST) X-Google-Smtp-Source: AFSGD/U5atMlwGq2I6Bw8ipj1ViGJeGBWO3/EmNBL963MfCVTMDCBQATHR/x6O4jiorj5DV09xeB X-Received: by 2002:a62:62c5:: with SMTP id w188mr17972899pfb.160.1543879749108; Mon, 03 Dec 2018 15:29:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543879749; cv=none; d=google.com; s=arc-20160816; b=uqAx2tljVOX3zlIPC0m63X/fQHc78Cj7itJd1c6fmrvvK8Jcyv0aFsda1IqbfQDB7u pNFTvTDRgXQkXuWyJsZtd7fSH21tkSwWL+YqXA2W55BIbqUadiq3B1AeFP5JpI9Ru4qr sWqUChM+9mT910cJjtJLjot2VOxb8U13adNQBlS0gf5XuBgYddRfMQrGC08MAUcYBXY0 UGttkrb+XGdD1UeOUxpNVIxH4idgDNT332hCZxG6MEaKx+6ZW1a8HCMzwQxI0BPjNSQW BPKjIWVW7kZEvkoLIZKBzz4nli53dkQfjoAXymykwMMFBIgjA6mu+gjwwJpFKHL15EoT gSOQ== 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=Xsnx777dnp60qOJRp6DiaP6WDfZUuGwjTpf8nB7zqFQ=; b=vh9bp/SXL9Sy0sGC7ixQhi1WcAwtctRMCH9MB/+aXA32TzoQlloLvkumRHTKQFoeH1 PMDZ09iB5MX2i00oIHAD+wTUAOeXD34/BYICqg5wp1p0RkFwihPdQaJh+xYV20cBvEcj vczDHLTjC7nyvesHraEJcpBB8pKeYGYRMhmJgV1Qm9fPfupyhmIAA/JcRQOm6b6jrDxU ZyCVZhm6HH86cgs7TkwG1y71AzH5BWvwg3Q5Yr6MPG+vTVOfgTdy/AwxFyTQSXEt3ckw TLjCrZFgZKPlhNm4B22Cfvos8R6bJMRUjtUHuEh7rofjiskjwW91WLLsBbaCGa9aDcE0 gD2g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=MUA+QTYl; 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 128si16144077pfe.4.2018.12.03.15.28.54; Mon, 03 Dec 2018 15:29:09 -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=pass header.i=@paul-moore-com.20150623.gappssmtp.com header.s=20150623 header.b=MUA+QTYl; 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 S1726071AbeLCX2O (ORCPT + 99 others); Mon, 3 Dec 2018 18:28:14 -0500 Received: from mail-lf1-f66.google.com ([209.85.167.66]:38644 "EHLO mail-lf1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726053AbeLCX2M (ORCPT ); Mon, 3 Dec 2018 18:28:12 -0500 Received: by mail-lf1-f66.google.com with SMTP id p86so10525699lfg.5 for ; Mon, 03 Dec 2018 15:28:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=paul-moore-com.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=Xsnx777dnp60qOJRp6DiaP6WDfZUuGwjTpf8nB7zqFQ=; b=MUA+QTYlQlsdMUPiaO/+eevkriVRWDKNWRfiPdLTUb03vwFJvce0Sgi4uez38pg0ts j11r+I7AZm+lTxiLq5DEl/xanK/zEEmdeD7tjU2GjrB23ZuOWBDgurZH/Ug+InIvKjZw o7wTTvX/Y80cpECHe4xb5c+HCbdCB0qMysZBrDGH1S1+2bjckaapcFE0XmEYqI5sqK3C SCl6tuY/1iG4iGaJSN9++3zf5d67Y629uwRVvGEKLF6hWKq52bgLMrkvXgQbXPlDvgVv YQRvEUA39qdKiZ77k2T30iCfnL23T04NlpJM48zftpS9cLQtJa0R5lWfmRpibIASu1Zo xQzg== 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=Xsnx777dnp60qOJRp6DiaP6WDfZUuGwjTpf8nB7zqFQ=; b=SfKKMme/9R+bdVhJSC+/+dLzAblg94HncrUNaqwDz8id98NBkXXWv+ihv4NlDV3fNG Pn3wPeb4sTm4MYcALQ00RSQIxgP7QPEQN1EsIyYiftRUka2nhecw/p7K1yPTSicloV1S JLnzAm8fnuc2883O9fSRVbTuDpJjNYkmo3m0gZSvxJ/BjxIRPaUccPyS8Pfaw1U3uqS4 x2Lj8QZIkPTga7d54dfSMPx2bqTvEpcXIqukN/elytVG3VjhNjyOrelrgFr3il6ghs47 qKwy49nI18A/tVbQA1KZ2yrBEfTaRx8+VhoUA+JvrZ8bWbiaSa+uLODQzJRlDNwBTWHC LToQ== X-Gm-Message-State: AA+aEWYJ66C7Ulu9roVzXrTqD0nDlTAOjbBYmNMJZGA1t2ed0qnZumK2 I/hiONzW0NH0IrBM8fWUzUE8WS+21EQPrzY2kPNh X-Received: by 2002:a19:a7c1:: with SMTP id q184mr9870170lfe.4.1543879689460; Mon, 03 Dec 2018 15:28:09 -0800 (PST) MIME-Version: 1.0 References: <20181127210542.GA2599@redhat.com> <20181128170302.GA12405@redhat.com> <377b7d4f-eb1d-c281-5c67-8ab6de77c881@tycho.nsa.gov> <26bce3be-49c2-cdd8-af03-1a78d0f268ae@tycho.nsa.gov> <6b125e8e-413f-f8e6-c7ae-50f7235c8960@tycho.nsa.gov> In-Reply-To: From: Paul Moore Date: Mon, 3 Dec 2018 18:27:57 -0500 Message-ID: Subject: Re: overlayfs access checks on underlying layers To: Dan Walsh Cc: miklos@szeredi.hu, Stephen Smalley , vgoyal@redhat.com, omosnace@redhat.com, bfields@fieldses.org, salyzyn@android.com, linux-kernel@vger.kernel.org, linux-unionfs@vger.kernel.org, linux-fsdevel@vger.kernel.org, selinux@vger.kernel.org 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 Thu, Nov 29, 2018 at 5:22 PM Daniel Walsh 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? > > Yes, in the case of context mount, it will get the context mount directory. > > In the case of not context mount, it should maintain the label of the > lower. > > > Next question: permission to change metadata is tied to permission to > > open? Is it possible that open is denied, but metadata can be > > changed? > > Yes, SElinux handles open differently then setattr. Although I am not > sure if any tools handle this. > > > 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? > > After talking to Vivek, I am not sure their is a privilege escallation. More on this below, but this thread doesn't have me convinced, and we are at -rc5 right now. We need to come to some decision on this soon because we are running out of time before v4.20 is released with this code. > For device nodes, the mounter has to have the ability to create the > devicenode with the context mount, if he can do this, then he can do it > with or without Overlay. This might lead to users making mistakes on > security, but the model is sound. And I think this stands even in the > case of the lower is mounted NODEV and the upper is not. If the mounter > can create a device on the upper with a particular label, then he does > not need the lower. The problem I have when looking at the current code is that permission is given, regardless of what is requested, for any special_file() on an overlayfs mount. It also looks like the mounter's creds are used when checking permissions regardless of the file has been copied up or not; I would expect that the mounter's permissions would only used when checking permissions against the lower inode, no? I think there is also some weird behavior if the underlying inode only allows the mounter to write (no read) and a write is requested at the overlayfs layer. I'm sure I'm missing some subtle thing with overlayfs, but why aren't we doing something like the following: int ovl_permission(...) { if (!realinode) { ... } err = generic_permission(inode, mask); if (err) return err; if (upperinode) { err = inode_permission(upperinode, mask); } else { // on the lower inode, always use the mounter's creds old_cred = ovl_override_creds(...); // check to see if we have the right perms first, if // that fails switch to a read/copy-up check if we // are doing a write (note: we are not bypassing the // exec check, the task can change the metadata like // every other fs) err = inode_permission(lowerinode, mask); if (err && (mask & (MAY_EXEC | MAY_APPEND))) { // PM: my guess is that we also need to add a // "&& !special_file(lowerinode)" to the conditional // above because you can't copy-up a dev node in the // normal sense, but we'll leave that as a discussion // point for now... // turn the write into a read (copy-up) mask &= ~(MAY_WRITE | MAY_APPEND); mask |= MAY_READ; err = inode_permission(lowerinode, mask); } // reset the creds revert_creds(old_cred); } return err; } > For sockets, I see the case where a process is listening on the lower > level socket, the mounter mounts the overlay over the directory with the > socket. Then the mounter changes the attributes of the socket, > performing a copy up. If the mounter can not talk to the socket and the > other end is still listening, then this could be an issue. If the > socket is no longer connected to the listener on the lower, then this is > not an issue. > > Similar for a FIFO. See my comment "// PM: my guess ..." in the pseudo code above. I think the write->read permission mask conversion really should only apply to normal files where you can do a copy-up. > With SELinux we are also always checking not only the file access to the > socker, but also checking whether the label of the client is able to > talk to the label of the server daemon. So we are protected by a > secondary check. That's making some assumptions on the LSM and the LSM's loaded policy and is not something I would want to rely on. -- paul moore www.paul-moore.com