From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-0.7 required=3.0 tests=DKIM_INVALID,DKIM_SIGNED, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_PASS,T_MIXED_ES autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4F19FC67839 for ; Thu, 13 Dec 2018 16:10:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F35212054F for ; Thu, 13 Dec 2018 16:10:18 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=tycho.nsa.gov header.i=@tycho.nsa.gov header.b="Epp5Dfmq" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org F35212054F Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=tycho.nsa.gov Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=selinux-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728244AbeLMQKN (ORCPT ); Thu, 13 Dec 2018 11:10:13 -0500 Received: from upbd19pa10.eemsg.mail.mil ([214.24.27.85]:54741 "EHLO upbd19pa10.eemsg.mail.mil" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728059AbeLMQKN (ORCPT ); Thu, 13 Dec 2018 11:10:13 -0500 X-EEMSG-check-008: 186847030|UPBD19PA10_EEMSG_MP10.csd.disa.mil Received: from emsm-gh1-uea10.ncsc.mil ([214.29.60.2]) by upbd19pa10.eemsg.mail.mil with ESMTP/TLS/DHE-RSA-AES256-SHA256; 13 Dec 2018 16:10:04 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=tycho.nsa.gov; i=@tycho.nsa.gov; q=dns/txt; s=tycho.nsa.gov; t=1544717405; x=1576253405; h=subject:to:cc:references:from:message-id:date: mime-version:in-reply-to:content-transfer-encoding; bh=1o873b0JilHc41AIAQGfpwRMp5Q4g4cDK0+LGW7bCK8=; b=Epp5DfmqmKidwhGsXKSFNr6Xexj53FvCFWhwmJ31+Y8ub1vr4ucsclxT vlkHgG6wgp/hmU74uXralxXdtqn2r7gfYFwkdCb9yQm00XD8kXkWivQ1x s2Fp1E7NqMYLDGvyJAhFiYHCqUSYzBaWCtu1yAA03rqAZiiJsq+P333u2 c01O7P6+ZDjGUHQQxGsLZBkMxM4vfIMwH0RmmxoCDxobVD+4gFyJPERfi OHilwzE7xM9GT7cUy9yv4OCyyl+0LIdUDpa5v3LPm7YHAirwp5qBshzD8 lcWiYi6d0HjkDCxcBnPrmlncWirwXpy4YzSL6IN9+BrBW5wC/oVt/akNA w==; X-IronPort-AV: E=Sophos;i="5.56,349,1539648000"; d="scan'208";a="18686255" IronPort-PHdr: =?us-ascii?q?9a23=3ACPWNvhMLqFRiJT85hQ0l6mtUPXoX/o7sNwtQ0K?= =?us-ascii?q?IMzox0K//zp8bcNUDSrc9gkEXOFd2Cra4c26yO6+jJYi8p2d65qncMcZhBBV?= =?us-ascii?q?cuqP49uEgeOvODElDxN/XwbiY3T4xoXV5h+GynYwAOQJ6tL1LdrWev4jEMBx?= =?us-ascii?q?7xKRR6JvjvGo7Vks+7y/2+94fcbglUhzexe69+IAmrpgjNq8cahpdvJLwswR?= =?us-ascii?q?XTuHtIfOpWxWJsJV2Nmhv3+9m98p1+/SlOovwt78FPX7n0cKQ+VrxYES8pM3?= =?us-ascii?q?sp683xtBnMVhWA630BWWgLiBVIAgzF7BbnXpfttybxq+Rw1DWGMcDwULs5Qi?= =?us-ascii?q?qp4bt1RxD0iScHLz85/3/Risxsl6JQvRatqwViz4LIfI2ZMfxzca3HfdMeWG?= =?us-ascii?q?FPQMBfWSJcCY+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ascii?q?F9G8+8gRzZwyWqBLoVnaSRBJMo6qLcw2TxJ8FlxnbC1akhiUQmQ8RWOW2lmK?= =?us-ascii?q?F/7Q7TCJDNk0iCiaaqeroT3DTX+GeA02WOpkdYXxB0UanfWnAffETWp8zj5k?= =?us-ascii?q?zeV7+uFagnMgxZxM6GK6tKbMDpjFpfSPf+PtTeYmWxm2G+BRaT3b6McoXqdH?= =?us-ascii?q?sH3CnHC0gLjRoT/XCYOgg6HCuhpHjeDDN2H1L1f0zs6fV+qG+8TkIsywGKbk?= =?us-ascii?q?th16e6+xIMi/ycUO4c0awauCg/rzV5B0i9393IBNqavQZhf7tTYck74FhZ0W?= =?us-ascii?q?LVrQt9PoavL6p6nF4Rbxx3v1/y1xVwEohAitYlrHcrzAp0NKKZ30hMdy2X3Z?= =?us-ascii?q?/uIL3bMGry8w61a67QxF7e1Mya+qAV6PQ3s1/jph2mFlI+83V71NlYy2aT55?= =?us-ascii?q?vQAwoWSpLxUl069wJkqL7HYiky/Z/U2WdwPqmztz+Rk+4uUdUk1BujN/hYIa?= =?us-ascii?q?qAXFvsHMoLDsyGMuEmm1G1KBkDObYB2rQzOpada/ae2KOtdN1llTaigHUPtJ?= =?us-ascii?q?txyWqQ5iF8TajOxJ9DzPaGiFjUHwzghUus55ik0btPYisfSy/mk3Dp?= X-IPAS-Result: =?us-ascii?q?A2CBAAD+ghJc/wHyM5BjHAEBAQQBAQcEAQGBUwUBAQsBg?= =?us-ascii?q?VopgWgng3yUeQUGgQgIJYkhjjOBejgBhEACgwMiNgcNAQMBAQEBAQECAWwog?= =?us-ascii?q?jYkAYJhAQEBAQIBIxU0CgMQCw4KAgImAgJXBg0GAgEBF4JHP4F0BQinFYEvh?= =?us-ascii?q?UCEcYELizEXeIEHgREnDIJfhDuDSoJXAokqggiEXDdRj3kJkVMGGIFciEaHK?= =?us-ascii?q?JsWDCWBVisIAhgIIQ+DJ4InF447IQMwgQUBAYoKgj4BAQ?= Received: from tarius.tycho.ncsc.mil ([144.51.242.1]) by EMSM-GH1-UEA10.NCSC.MIL with ESMTP; 13 Dec 2018 16:10:02 +0000 Received: from moss-pluto.infosec.tycho.ncsc.mil (moss-pluto.infosec.tycho.ncsc.mil [192.168.25.131]) by tarius.tycho.ncsc.mil (8.14.4/8.14.4) with ESMTP id wBDG9wDa024080; Thu, 13 Dec 2018 11:09:58 -0500 Subject: Re: overlayfs access checks on underlying layers To: Vivek Goyal 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 References: <20181204152248.GB21509@redhat.com> <20181204154243.GA16818@redhat.com> <665ec6f3-f16d-681f-30d5-eface14c9808@tycho.nsa.gov> <20181204161747.GC16818@redhat.com> <20181205134317.GA11337@redhat.com> <8eb7f677-fd71-c31b-bfed-29fb7187d132@tycho.nsa.gov> <20181211214821.GD17242@redhat.com> <2e4d90ce-61e7-56b1-c161-4e5fb7236537@tycho.nsa.gov> <20181213145813.GB4384@redhat.com> From: Stephen Smalley Message-ID: <846eb23e-1188-9e45-ee0a-676d26cc715e@tycho.nsa.gov> Date: Thu, 13 Dec 2018 11:12:31 -0500 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.3.1 MIME-Version: 1.0 In-Reply-To: <20181213145813.GB4384@redhat.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: selinux-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: selinux@vger.kernel.org On 12/13/18 9:58 AM, Vivek Goyal wrote: > On Wed, Dec 12, 2018 at 09:51:59AM -0500, Stephen Smalley wrote: >> On 12/11/18 4:48 PM, Vivek Goyal wrote: >>> On Thu, Dec 06, 2018 at 03:26:26PM -0500, Stephen Smalley wrote: >>>> On 12/5/18 8:43 AM, Vivek Goyal wrote: >>>>> On Tue, Dec 04, 2018 at 11:49:16AM -0500, Stephen Smalley wrote: >>>>>> On 12/4/18 11:17 AM, Vivek Goyal wrote: >>>>>>> On Tue, Dec 04, 2018 at 11:05:46AM -0500, Stephen Smalley wrote: >>>>>>>> On 12/4/18 10:42 AM, Vivek Goyal wrote: >>>>>>>>> On Tue, Dec 04, 2018 at 04:31:09PM +0100, Miklos Szeredi wrote: >>>>>>>>>> On Tue, Dec 4, 2018 at 4:22 PM Vivek Goyal wrote: >>>>>>>>>> >>>>>>>>>>> Having said that, this still create little anomaly when mknod to client >>>>>>>>>>> is not allowed on context label. So a device file, which is on lower >>>>>>>>>>> and client can not open it for read/write on host, it can now be opened >>>>>>>>>>> for read/write because mounter will allow access. So why it is different >>>>>>>>>>> that regular copy up. Well, in regular copy up, we created a copy of >>>>>>>>>>> the original object and allowed writing to that object (cp --preserve=all) >>>>>>>>>>> model. But in case of device file, writes will go to same original >>>>>>>>>>> object. (And not a separate copy). >>>>>>>>>> >>>>>>>>>> That's true. >>>>>>>>>> >>>>>>>>>> In that sense copy up of special file should result in upper having >>>>>>>>>> the same label as of lower, right? >>>>>>>>> >>>>>>>>> I guess that might be reasonable (if this behavior is a concern). So even >>>>>>>>> after copy up, client will not be able to read/write a device if it was >>>>>>>>> not allowed on lower. >>>>>>>>> >>>>>>>>> Stephen, what do you think about retaining label of lower for device >>>>>>>>> files during copy up. What about socket/fifo. >>>>>>>> >>>>>>>> We don't check client task access to the upper inode label, only to the >>>>>>>> overlay, right? So the client is still free to access the device through >>>>>>>> the overlay even if we preserve the lower inode label on the upper inode? >>>>>>>> What do we gain? >>>>>>> >>>>>>> That's only with latest code and Miklos said he will revert it for 4.20. >>>>>>> >>>>>>> IOW, I am assuming that we will continue to check access to a file >>>>>>> on upper in the context of mounter. Otherwise, client will be able to access >>>>>>> files on upper/ which even mounter can't access. >>>>>> >>>>>> I was assuming we're talking about the proposed solution, where we check >>>>>> client access to the overlay (unchanged), mounter access to lower >>>>>> (unchanged), copy-up if denied (new), mounter access to upper (new in the >>>>>> sense that previously we didn't copy-up on denials). >>>>>> >>>>>> In that situation, propagating the lower inode label to the upper inode only >>>>>> impacts the mounter checks, and in that case makes copy-up pointless - if it >>>>>> wasn't allowed to lower it won't be allowed to upper. If it is allowed, >>>>>> then client task is free to access the device regardless as long as it has >>>>>> permissions to the overlay inode. So I don't see what we gain by >>>>>> propagating the lower inode label to the upper inode in the context mount >>>>>> case, and it creates an inconsistency between special files and regular >>>>>> ones. >>>>> >>>>> If we agree on retaining lower label of lower device file on copy up, then >>>>> I am assuming we will change rule c) to copy up only non device files. >>>>> (because if you don't have access on lower, you will not have access >>>>> even after copy up). >>>>> >>>>> There are other paths where copy up happnes. Like link or when file >>>>> metadata (ownership, permissions, timestmap) changes. In those cases, >>>>> if we retain the lower label over copy up, it probably will help. >>>>> >>>>> IOW, just by creating a link to a device, one will not get access to >>>>> a device on upper which could not be accessed on lower. >>>>> >>>>> Device files are special anyway. In regular files we are creating a >>>>> copy and user writes to copy. But that's not the case with device >>>>> files. So I guess these will have to be treated differently. >>>> >>>> I don't understand what you are suggesting. In the case of a context mount, >>>> the context specified by the mounter must be assigned to the upper inode for >>>> any files that are copied up. Otherwise, changes to file data or metadata >>>> made through the overlay will be visible under two different security >>>> contexts simultaneously: the context of the overlay inode (i.e. the one >>>> specified by the mounter) and the context of the upper inode (in your >>>> suggestion, the context from the lower inode). This allows a violation of >>>> MAC policy where one can leak data through an overlay to an unauthorized >>>> context. >>> >>> Hi Stephen, >>> >>> Sorry, I don't understand this point of leaking data through overlay. Even >>> if we retain lower label on copy up (for device file), to open that file >>> process should have access on overlay context label and then mounter needs >>> to have access on upper inode (lower label). This is not different from >>> opening a file on lower. Just that metadata of this file on upper might >>> be different. >>> >>> Can you elaborate a bit more on how this is leaking data through overlay >>> mount. If it is, then why accessing file on lower is not equivalent of >>> leaking of data. >> >> In the container use case, retaining the lower label on copy-up for a >> context-mounted overlay permits a process in the container to leak the >> container data out to host files not labeled with the container label and >> thus potentially accessible to other containers or host processes. > >> The >> container process appears to just be writing to files labeled with the >> container label via the overlay, but the written data and/or metadata is >> directly accessible through the lower label, which is likely readable to >> all/many containers and host processes. >> >> In the multi-level security (MLS) use case, an analogy would a situation >> where you have an unclassified lower dir with some content to be shared >> read-only across all levels, and an overlay is context-mounted at each level >> with a corresponding upper dir and work dir private to that level. If a >> client process at secret performs a write to a file via the secret overlay, >> and if the written data is stored in a file in the upper dir that inherits >> the label from the lower file (unclassified), then the secret process can >> leak data to unclassified processes at will, violating the MLS policy. > > For the case of devices, its already happening. One might change metadata > of a device (hence trigger copy up). Now all writes to upper device file > from secret process still go to same underlying device and are still > readable from lower device file. This is an argument for not copying up device files IMHO, not for preserving the lower label on them. Even just allowing the secret process to trigger the creation of an unclassified file through copy-up is a violation of the MLS policy. It doesn't require writing to the file itself. > > In fact, for the case of devices, that is even more of a reason to retain > the label same as lower. Otherwise upper device node is leaking data > of a secret process which can be accessed using device at lower/ (lower's > label is readable). > >> >> The difference with the lower is that it is read-only and the mounter is >> explicitly choosing to export it under the new context for reading (but not >> for writing). > > If we retain the label and if lower is not writable, then upper deivce > node is not being written to as well. So from label point of view, lower > and upper inode are not different. Only difference is that some metadata > of upper inode might be different. > > Thanks > Vivek >> >> As a side note, the actual checking during a context mount isn't as granular >> as we might like here, since there is no overlay-specific logic and thus no >> individual checking of the lower, upper, and work directory labels.