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=-3.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 0436CC4363D for ; Thu, 24 Sep 2020 22:07:36 +0000 (UTC) Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by mail.kernel.org (Postfix) with ESMTP id 7CF0221D91 for ; Thu, 24 Sep 2020 22:07:35 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7CF0221D91 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linux.intel.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=owner-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix) id 707F28E0001; Thu, 24 Sep 2020 18:07:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 6936D6B005D; Thu, 24 Sep 2020 18:07:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 580D78E0001; Thu, 24 Sep 2020 18:07:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0096.hostedemail.com [216.40.44.96]) by kanga.kvack.org (Postfix) with ESMTP id 401AB6B005C for ; Thu, 24 Sep 2020 18:07:34 -0400 (EDT) Received: from smtpin09.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay02.hostedemail.com (Postfix) with ESMTP id 042481DFC for ; Thu, 24 Sep 2020 22:07:34 +0000 (UTC) X-FDA: 77299342428.09.box46_2d1260927162 Received: from filter.hostedemail.com (10.5.16.251.rfc1918.com [10.5.16.251]) by smtpin09.hostedemail.com (Postfix) with ESMTP id DCD94180AD801 for ; Thu, 24 Sep 2020 22:07:33 +0000 (UTC) X-HE-Tag: box46_2d1260927162 X-Filterd-Recvd-Size: 4932 Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by imf46.hostedemail.com (Postfix) with ESMTP for ; Thu, 24 Sep 2020 22:07:32 +0000 (UTC) IronPort-SDR: 4ONn8fVhQIGMX3LFFdrTwf/rqPlHeWPkTOExadSwo3ECZsBZ2LT8T4jGgJyz25ujKfH+n4N1pD bVvvDCv8GkXw== X-IronPort-AV: E=McAfee;i="6000,8403,9754"; a="140789919" X-IronPort-AV: E=Sophos;i="5.77,299,1596524400"; d="scan'208";a="140789919" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga106.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2020 15:07:31 -0700 IronPort-SDR: QJwZR0Nm4vfxw/6m+Na3H+P/Txy3Pb6QGCM1+l9cNF0xHfTla8oRrqEMspV3Li5tLs0mufdpSs elkBzcAbsiTg== X-IronPort-AV: E=Sophos;i="5.77,299,1596524400"; d="scan'208";a="487143228" Received: from yshmidtx-mobl1.ger.corp.intel.com (HELO localhost) ([10.252.63.233]) by orsmga005-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 24 Sep 2020 15:07:24 -0700 Date: Fri, 25 Sep 2020 01:07:22 +0300 From: Jarkko Sakkinen To: Dave Hansen Cc: Sean Christopherson , Haitao Huang , Andy Lutomirski , X86 ML , linux-sgx@vger.kernel.org, LKML , Linux-MM , Andrew Morton , Matthew Wilcox , Jethro Beekman , Darren Kenny , Andy Shevchenko , asapek@google.com, Borislav Petkov , "Xing, Cedric" , chenalexchen@google.com, Conrad Parker , cyhanish@google.com, "Huang, Haitao" , Josh Triplett , "Huang, Kai" , "Svahn, Kai" , Keith Moyer , Christian Ludloff , Neil Horman , Nathaniel McCallum , Patrick Uiterwijk , David Rientjes , Thomas Gleixner , yaozhangx@google.com Subject: Re: [PATCH v38 10/24] mm: Add vm_ops->mprotect() Message-ID: <20200924220722.GE119995@linux.intel.com> References: <20200921211849.GA25403@linux.intel.com> <20200922052957.GA97272@linux.intel.com> <20200922053515.GA97687@linux.intel.com> <20200922164301.GB30874@linux.intel.com> <20200923135056.GD5160@linux.intel.com> <20200924192853.GA18826@linux.intel.com> <20200924200156.GA19127@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Organization: Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On Thu, Sep 24, 2020 at 01:10:31PM -0700, Dave Hansen wrote: > On 9/24/20 1:01 PM, Sean Christopherson wrote: > >> In pseudo-C, it's something logically like this for the "nice" case: > >> > >> ptr = mmap("/some/executable", PROT_EXEC); > >> ioctl(sgx_fd, ADD_ENCLAVE_PAGE, SGX_PROT_EXEC, ptr, size); > >> mmap(sgx_fd); > >> EENTER; > >> > >> And we're trying to thwart: > >> > >> ptr = mmap("/mnt/noexec/file", PROT_READ); > >> ioctl(sgx_fd, ADD_ENCLAVE_PAGE, SGX_PROT_EXEC, ptr, size); > >> mmap(sgx_fd); > >> EENTER; > >> > >> because that loads data into the enclave which is executable but which > >> was not executable normally. But, we're allowing this from anonymous > >> memory, so this would seem to work: > >> > >> ptr = mmap("/mnt/noexec/file", PROT_READ); > >> buffer = malloc(PAGE_SIZE); > >> memcpy(buffer, ptr, PAGE_SIZE); > >> // need mprotect(buf, PROT_EXEC)??? > >> ioctl(sgx_fd, ADD_ENCLAVE_PAGE, SGX_PROT_EXEC, buffer, size); > >> mmap(sgx_fd); > >> EENTER; > >> > >> and give the same result. What am I missing? > > The last example, where the enclave is copied to a buffer, is out of scope > > for noexec. But, it is in scope for LSMs, e.g. for this last example, we > > could add an LSM upcall so that SELinux could require PROCESS_EXECMEM (or an > > SGX specific equivalent). > > Why don't we just declare enclave memory as "out of scope for noexec" in > the same way that anonymous memory is, and just discard this patch? > That doesn't seem too much of a stretch. I did that already for v39. It unconditionally discards noexec partitions. I see EMODPE as the key driver for this patch, not noexec partitions. I.e. post you've done SGX_IOC_ENCLAVE_INIT you are capped when it comes to permissions. /Jarkko