Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp2164057yba; Fri, 17 May 2019 11:37:17 -0700 (PDT) X-Google-Smtp-Source: APXvYqzSKpGA8US19jUMdjrDGBUhSz0P1YRcy1+t1VhOy5d5zq2j0fbMIyQBRwXLQBlix30ivagG X-Received: by 2002:a62:d286:: with SMTP id c128mr63640956pfg.159.1558118237264; Fri, 17 May 2019 11:37:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1558118237; cv=none; d=google.com; s=arc-20160816; b=TsJ0NVDXKJFNVGvxrq566089nz00G68qwTEmkcyaLfEEOXng2X6EvIxH3T0bu6YRTL 3Xoyed6jXS5QkDZSclaOElCWiTJPsEj0hLl+Hdg738wQYwUdodOv/RvqJJ+wm9n0OKwt /bQhNPuk/fa8PKgST3pTflmmoKdOSvvaxWb/9slWKWT2tjsp/xQO+Ozi3dzyb2lwig4+ 3kvJQVNG08FUl3JMklAihAVf9WrlSiSvYL70STPetP4vuDhlcn23sfLJSccIMvQOeq5d fqSb7mF4ay2o5auzDuZoXNXayHXKLy0Up40vw8pcWEBnkmkd6SrZL6DfaNlG3FslSpa6 XuhQ== 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-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=Zkrw2SwHhCSL3eSlJbSKiHxKHFqW9SM7sJ6Wo+vOqjQ=; b=VRsWkniHDmp3AAOe5X70hxAmg5CKohNIrCyW3KWtKzNyljNQrCLO6+Gk/nsYFhZh1B zpPJRbTSph6kuLzsmRN7EPYlNlP9JCsf0vcfIDFbOUhR/Rir/pGUkCjfRPN5KQnOo8Jk 0y3cdhKX2orGxUZ/RlRi89FxDN/dBEnKZm5nv4imFKeYh/c3M3SFHpH9oqF5JX5kHawu TgpA7pX0nvVAEi1IjfddlONv1BGig5Eh9hexCMMmED9zbHGdUkaktsGl/1x7VoizAwNE BK45AVM7ecaCBBtj5ka83XwsygA88Byyix15q2Eos+O9eGcmXS16reWZr6sMgS9KkhOl gKxw== 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=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 7si9343745pll.99.2019.05.17.11.37.01; Fri, 17 May 2019 11:37:17 -0700 (PDT) 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=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728467AbfEQR34 (ORCPT + 99 others); Fri, 17 May 2019 13:29:56 -0400 Received: from mga12.intel.com ([192.55.52.136]:29922 "EHLO mga12.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726078AbfEQR34 (ORCPT ); Fri, 17 May 2019 13:29:56 -0400 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 17 May 2019 10:29:55 -0700 X-ExtLoop1: 1 Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.36]) by fmsmga005.fm.intel.com with ESMTP; 17 May 2019 10:29:54 -0700 Date: Fri, 17 May 2019 10:29:53 -0700 From: Sean Christopherson To: Stephen Smalley Cc: "Xing, Cedric" , Andy Lutomirski , James Morris , "Serge E. Hallyn" , LSM List , Paul Moore , Eric Paris , "selinux@vger.kernel.org" , Jarkko Sakkinen , Jethro Beekman , "Hansen, Dave" , Thomas Gleixner , "Dr. Greg" , Linus Torvalds , LKML , X86 ML , "linux-sgx@vger.kernel.org" , Andrew Morton , "nhorman@redhat.com" , "npmccallum@redhat.com" , "Ayoun, Serge" , "Katz-zamir, Shay" , "Huang, Haitao" , Andy Shevchenko , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes Subject: Re: SGX vs LSM (Re: [PATCH v20 00/28] Intel SGX1 support) Message-ID: <20190517172953.GC15006@linux.intel.com> References: <960B34DE67B9E140824F1DCDEC400C0F654E38CD@ORSMSX116.amr.corp.intel.com> <960B34DE67B9E140824F1DCDEC400C0F654E3FB9@ORSMSX116.amr.corp.intel.com> <6a97c099-2f42-672e-a258-95bc09152363@tycho.nsa.gov> <20190517150948.GA15632@linux.intel.com> <80013cca-f1c2-f4d5-7558-8f4e752ada76@tycho.nsa.gov> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <80013cca-f1c2-f4d5-7558-8f4e752ada76@tycho.nsa.gov> User-Agent: Mutt/1.5.24 (2015-08-30) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, May 17, 2019 at 12:37:40PM -0400, Stephen Smalley wrote: > On 5/17/19 12:20 PM, Stephen Smalley wrote: > >On 5/17/19 11:09 AM, Sean Christopherson wrote: > >>I think we may want to change the SGX API to alloc an anon inode for each > >>enclave instead of hanging every enclave off of the /dev/sgx/enclave > >>inode. > >>Because /dev/sgx/enclave is NOT private, SELinux's file_map_prot_check() > >>will only require FILE__WRITE and FILE__EXECUTE to mprotect() enclave > >>VMAs > >>to RWX.? Backing each enclave with an anon inode will make SELinux treat > >>EPC memory like anonymous mappings, which is what we want (I think), e.g. > >>making *any* EPC page executable will require PROCESS__EXECMEM (SGX is > >>64-bit only at this point, so SELinux will always have default_noexec). > > > >I don't think we want to require EXECMEM (or equivalently both FILE__WRITE > >and FILE__EXECUTE to /dev/sgx/enclave) for making any EPC page executable, > >only if the page is also writable or previously modified.? The intent is > >to prevent arbitrary code execution without EXECMEM (or > >FILE__WRITE|FILE__EXECUTE), while still allowing enclaves to be created > >without EXECMEM as long as the EPC page mapping is only ever mapped RX and > >its initial contents came from an unmodified file mapping that was > >PROT_EXEC (and hence already checked via FILE__EXECUTE). The idea is that by providing an SGX ioctl() to propagate VMA permissions from a source VMA, EXECMEM wouldn't be required to make an EPC page executable. E.g. userspace establishes an enclave in non-EPC memory from an unmodified file (with FILE__EXECUTE perms), and the uses the SGX ioctl() to copy the contents and permissions into EPC memory. > Also, just to be clear, there is nothing inherently better about checking > EXECMEM instead of checking both FILE__WRITE and FILE__EXECUTE to the > /dev/sgx/enclave inode, so I wouldn't switch to using anon inodes for that > reason. Using anon inodes also unfortunately disables SELinux inode-based > checking since we no longer have any useful inode information, so you'd lose > out on SELinux ioctl whitelisting on those enclave inodes if that matters. The problem is that all enclaves are associated with a single inode, i.e. /dev/sgx/enclave. /dev/sgx/enclave is a char device whose purpose is to provide ioctls() and to allow mmap()'ing EPC memory. In no way is it associated with the content that actually gets loaded into EPC memory. The actual file that contains the enclave's contents (assuming the enclave came from a file) is a separate regular file that the SGX subsystem never sees. AIUI, having FILE__WRITE and FILE__EXECUTE on /dev/sgx/enclave would allow *any* enclave/process to map EPC as RWX. Moving to anon inodes and thus PROCESS__EXECMEM achieves per-process granularity.