Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp8250950imu; Tue, 4 Dec 2018 05:33:46 -0800 (PST) X-Google-Smtp-Source: AFSGD/VOV3+8/VnU1WShJ5Ut1UkbkjqQolgaVfI8j7fuuDEWX2koDnhU0BJz9Bb/rrA9gV0192Yq X-Received: by 2002:a62:e511:: with SMTP id n17mr19986352pff.71.1543930426168; Tue, 04 Dec 2018 05:33:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1543930426; cv=none; d=google.com; s=arc-20160816; b=htTp3tN570VbnhizDYvTcC/wdFkJxRR25Sdjay+pLOYDbencLfbZrndwcjkxPDNXkL c/uEqSdS5wPaqv1CVZgIzUZuxbHVgt75DjbawiroTT3cE7+AV4pGkZQm2lBAQ2kyFnFo 3xeQFx/kTcGOMYyqmpmWGOIrSnt2Aq36UUTgmBlWr/rMvrdzQKS4T3IzOUZojrpkzWw6 rFbxG5w21cs6UiwEAixM1uZjiRyKBGGrWdDwm/goIeq23O/l2Iq5MV2TFZm4W/Az8EQi vwkhpJOkcxmQDlETeoWuWp48yPUE2ooSOTHTJXkvUeYi8bFbMVm7mCQPQv9BgRU+UgUb wlpg== 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=fZ52Zx/KCfQfQv21h5YNtPxuM09B4zF9M/ZuuyDoMrQ=; b=scmO8nkDVAVLG/IhlCFCe6xqtz4lFQn+YUfqCFaS2izRuuSkQZdn7B3KieAmAxoSTh YgXf4Oxqh0yJQpxlaNc1CdJAsT4F+RywNKCMz7iRt5FuiMNeGBOQxui9lp5mzvr3/KzD s2H2j6vgn1lvwHQMDNq2+lXMOqo0zArEPcfh5Eyaj5NppuuIQ8SZKjWJDUs0kTJYNkuj xRyo+xkVSepSUEtQHAKOtOItO7/Wtt6iTLEv0btNB5F+x5AxmUkfR6lYPojPZMG8wIEr OBLdTdboDPwJr6eY4JsTJtJVNy1frCxsBn5NuasT8dzoGrIjDkhy0LsOHiFnAyQEzmWg zQdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=temperror (no key for signature) header.i=@szeredi.hu header.s=google header.b=cHHQbr3M; 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 9si15052437pgm.112.2018.12.04.05.33.24; Tue, 04 Dec 2018 05:33:46 -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=cHHQbr3M; 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 S1726435AbeLDNcX (ORCPT + 99 others); Tue, 4 Dec 2018 08:32:23 -0500 Received: from mail-it1-f193.google.com ([209.85.166.193]:37880 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726042AbeLDNcX (ORCPT ); Tue, 4 Dec 2018 08:32:23 -0500 Received: by mail-it1-f193.google.com with SMTP id b5so14383893iti.2 for ; Tue, 04 Dec 2018 05:32:22 -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=fZ52Zx/KCfQfQv21h5YNtPxuM09B4zF9M/ZuuyDoMrQ=; b=cHHQbr3Mmns6BUJ03hUGsrgk7GRKkG6Von1EliWGWTqBXlvfyOwXM2TcedI0YUsskS VYUTvu8sUJVjnuQE+Du3QnulF9lmjI2VyV0KDbSOYQaKbVcTpnqVOBtuRplOI2vnOVbV PpoS92cfzrjV9LV7xqw+b4q+n/ckrkmGHzeiQ= 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=fZ52Zx/KCfQfQv21h5YNtPxuM09B4zF9M/ZuuyDoMrQ=; b=NKyzF8B7IIxL2CHCF376TqqY2B0f9cbT4iHW+JnJ20xr9y5E2uXyDR2zxOq73/CHrv Q32f2ralF492BkaE2QLmHleIR5Z49bNeC3vICZqXvDXZEFzggohd7oj65E9XYZcyUzXn 6XsylNbGqs6U1u6LFS00bW5r/9qXAinVfzz2rT8HuWv/DHW24ed4K8MZAHgn75XlwI9F VDvMWTV9rhM0RNfX7KubsDI3dkfyUcDEmbX2o08NyhipOs7g4bbLgw4TfxC/EDqg7CaR pBZMUZYjGFyVoE+OdjH+h1ABI4pmljNJJy5ILYXRXVKirc7hBGSipsdeIKAaI53yxZln EtXQ== X-Gm-Message-State: AA+aEWbYRYK0ms7QD8hWkk2DWL58bvQK5+N8HHZ3DJOWTmvrLEHlBFLz shZYPjbZlFxTb88alET23KJVCDRhiT/6yuTTIakMAA== X-Received: by 2002:a24:710:: with SMTP id f16mr10278314itf.121.1543930342005; Tue, 04 Dec 2018 05:32:22 -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: Miklos Szeredi Date: Tue, 4 Dec 2018 14:32:09 +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 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. Thanks, Miklos