Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp3789902ybi; Sun, 2 Jun 2019 23:43:08 -0700 (PDT) X-Google-Smtp-Source: APXvYqyqFUsB4JLPUhk61mCP4dJl/pqriMN/gchxglT+1U4RCD5QiALWh0FcF/lC1nR3/dyLA0/i X-Received: by 2002:a17:902:9a49:: with SMTP id x9mr7191090plv.282.1559544188369; Sun, 02 Jun 2019 23:43:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559544188; cv=none; d=google.com; s=arc-20160816; b=QIXl5Z2qHpLMybzrctu9mz51I5KAmg4En4+Wb9tAxBLtbwvSqfXsdNdgFpS3s27GRp NwPkbQlt/XP3xKJqRxcwWtln+2hrcWVbddBnI2YAA5xS/pb/B3yRaOr3FLY5edgsmfSl xOBkUJiE4WNEDkHT6ZSqCQRjrlXckZ+f6VFwadpQvYsX6LU9HlPod6RDAzpxZA6lXSiw aoTghAcoOXhEXUCDYNJ6LABw6giRXAnh0jXlhUO1leMPvjceTeLAXbc58aqB/DcS8f2W 1v+Sw6UmrDOCNYprmmcram1Zn2APFbUV/2b5jWXBuDiJggvmUDb+Vp/x+DRFgX2tJkxz iBew== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:content-transfer-encoding :dlp-reaction:dlp-version:dlp-product:content-language :accept-language:in-reply-to:references:message-id:date:thread-index :thread-topic:subject:cc:to:from; bh=abJIY693f7MRNjoIDx9X/tMhw47pKKKeMN3m0G+ac80=; b=Lcw1oSMmYORTuSEUtAL8JTThqX0wYQFXoTcdwiANTS4b4TTM7kyqP6Qh9eDljWd/G/ Lo1atyjaPqVIp7GJDvAOqa2g+qfvr4gWGmjbuPey3r84mljym229o8PvyVFcvEvijCxF vkQizELzWahLIO+psmVcqYEgMn+5UMPHuwlgxoXTIzDNlVaedZT/fk5GENozqbiiTCLE e1GTpKNpmhY163bfhZVV5uekfr6HgozSfpu6Pv4kVXGw2CYypmC+Pq7LrgUecGNth7T6 CE8+qlCfbKVtNluHAI0mUye6TFhVoNt6YgpDaDxJlyHMexGoHcJy5ELhL7jz1ITHg9oH QGpA== 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 j18si16880680pgm.561.2019.06.02.23.42.52; Sun, 02 Jun 2019 23:43:08 -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 S1727036AbfFCG2z convert rfc822-to-8bit (ORCPT + 99 others); Mon, 3 Jun 2019 02:28:55 -0400 Received: from mga17.intel.com ([192.55.52.151]:29222 "EHLO mga17.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726383AbfFCG2z (ORCPT ); Mon, 3 Jun 2019 02:28:55 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga107.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 02 Jun 2019 23:28:54 -0700 X-ExtLoop1: 1 Received: from orsmsx105.amr.corp.intel.com ([10.22.225.132]) by orsmga005.jf.intel.com with ESMTP; 02 Jun 2019 23:28:54 -0700 Received: from orsmsx160.amr.corp.intel.com (10.22.226.43) by ORSMSX105.amr.corp.intel.com (10.22.225.132) with Microsoft SMTP Server (TLS) id 14.3.408.0; Sun, 2 Jun 2019 23:28:54 -0700 Received: from orsmsx116.amr.corp.intel.com ([169.254.7.165]) by ORSMSX160.amr.corp.intel.com ([169.254.13.155]) with mapi id 14.03.0415.000; Sun, 2 Jun 2019 23:28:54 -0700 From: "Xing, Cedric" To: "Christopherson, Sean J" , "Jarkko Sakkinen" CC: Andy Lutomirski , Stephen Smalley , James Morris , "Serge E . Hallyn" , LSM List , Paul Moore , Eric Paris , "selinux@vger.kernel.org" , Jethro Beekman , "Hansen, Dave" , "Thomas Gleixner" , 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 , "Roberts, William C" , "Tricca, Philip B" Subject: RE: [RFC PATCH 6/9] x86/sgx: Require userspace to provide allowed prots to ADD_PAGES Thread-Topic: [RFC PATCH 6/9] x86/sgx: Require userspace to provide allowed prots to ADD_PAGES Thread-Index: AQHVGAkiEcDZ+jyqSUy8jMAaVrxFBKaJZ0ng Date: Mon, 3 Jun 2019 06:28:53 +0000 Message-ID: <960B34DE67B9E140824F1DCDEC400C0F654ECC35@ORSMSX116.amr.corp.intel.com> References: <20190531233159.30992-1-sean.j.christopherson@intel.com> <20190531233159.30992-7-sean.j.christopherson@intel.com> In-Reply-To: <20190531233159.30992-7-sean.j.christopherson@intel.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-titus-metadata-40: eyJDYXRlZ29yeUxhYmVscyI6IiIsIk1ldGFkYXRhIjp7Im5zIjoiaHR0cDpcL1wvd3d3LnRpdHVzLmNvbVwvbnNcL0ludGVsMyIsImlkIjoiNjUzM2MxNGEtZTU4NS00MzhlLWFkOGEtYmUyYjNlYjIzMWQyIiwicHJvcHMiOlt7Im4iOiJDVFBDbGFzc2lmaWNhdGlvbiIsInZhbHMiOlt7InZhbHVlIjoiQ1RQX05UIn1dfV19LCJTdWJqZWN0TGFiZWxzIjpbXSwiVE1DVmVyc2lvbiI6IjE3LjEwLjE4MDQuNDkiLCJUcnVzdGVkTGFiZWxIYXNoIjoiak0rSWg0Mk1hbDJlUHVIRDd0bXRUMWF4XC8xYnFEVzVTMEdvWUkzNnNGbEU4cUNZamlCWmMxd2gza3ZvOTluNzAifQ== x-ctpclassification: CTP_NT dlp-product: dlpe-windows dlp-version: 11.0.600.7 dlp-reaction: no-action x-originating-ip: [10.22.254.138] Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 8BIT MIME-Version: 1.0 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org > From: Christopherson, Sean J > Sent: Friday, May 31, 2019 4:32 PM > > ...to support (the equivalent) of existing Linux Security Module functionality. > > Because SGX manually manages EPC memory, all enclave VMAs are backed by the same vm_file, > i.e. /dev/sgx/enclave, so that SGX can implement the necessary hooks to move pages in/out > of the EPC. And because EPC pages for any given enclave are fundamentally shared between > processes, i.e. > CoW semantics are not possible with EPC pages, /dev/sgx/enclave must always be MAP_SHARED. > Lastly, all real world enclaves will need read, write and execute permissions to EPC pages. > As a result, SGX does not play nice with existing LSM behavior as it is impossible to > apply policies to enclaves with any reasonable granularity, e.g. an LSM can deny access to > EPC altogether, but can't deny potentially dangerous behavior such as mapping pages RW->RW > or RWX. > > To give LSMs enough information to implement their policies without having to resort to > ugly things, e.g. holding a reference to the vm_file of each enclave page, require > userspace to explicitly state the allowed protections for each page (region), i.e. take > ALLOW_{READ,WRITE,EXEC} in the ADD_PAGES ioctl. > > The ALLOW_* flags will be passed to LSMs so that they can make informed decisions when the > enclave is being built, i.e. when the source vm_file is available. For example, SELinux's > EXECMOD permission can be required if an enclave is requesting both ALLOW_WRITE and > ALLOW_EXEC. > > Update the mmap()/mprotect() hooks to enforce the ALLOW_* protections, a la the standard > VM_MAY{READ,WRITE,EXEC} flags. > > The ALLOW_EXEC flag also has a second (important) use in that it can be used to prevent > loading an enclave from a noexec file system, on > SGX2 hardware (regardless of kernel support for SGX2), userspace could EADD from a noexec > path using read-only permissions and later mprotect() and ENCLU[EMODPE] the page to gain > execute permissions. By requiring ALLOW_EXEC up front, SGX will be able to enforce noexec > paths when building the enclave. ALLOW_* flags shall be kept internal to LSM. This patch is completely unnecessary.