Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp654767pxk; Thu, 24 Sep 2020 15:08:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmEs4JpYo67+T2Zu3HqE83cDoHwCY8O94xensXxjvPsVLLbHX18jLmDsdX2BJ3KS2OvBq3 X-Received: by 2002:a17:906:24d6:: with SMTP id f22mr717097ejb.85.1600985333291; Thu, 24 Sep 2020 15:08:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1600985333; cv=none; d=google.com; s=arc-20160816; b=re0UYk+0kl4yn6qPD9l5QB8m6BZNohPEi36YvTQ5hRi5b6EruyKTVL2ox5N9U8e8T4 gePLGCkT/pFQQS0PtI6galPGZE9hwDHGgs4Qj6np4gVALLZJxQZfVzBQZjEn0ZAaZtUe AsceLUWmJ5AW81EWNHpwEPhzffjVRsxbebLrWW0Ga6t3QhCjnUG3279g9PECYHF8c1PR oOhk4WQI1qiGsy1PXjCWAraBN/SvtxcHvg65rw1PD+8hakbGcDX+dQfFuJXsEIGLRQv7 dohK1R8ylzPpedL1lrJo0YmCeXgijlrk14WK4rlT/S9T3UBytE6KN9syeY6Y0CizmjhA DpLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:organization:in-reply-to:content-disposition :mime-version:references:message-id:subject:cc:to:from:date :ironport-sdr:ironport-sdr; bh=UcA1W5vrEP1bFYVUbbRJGQIRrTndEA4gvWtj2Ilabn8=; b=K9XmTF/O8c3W9ir+G4h91ItMhfG4gUPmE/dZm9+GEY4DqjveKfAqApfcg0ftg6hrsn lqcGNT1mAKkcvx9tjxkO5EY/5LSCCgVTM7WDwsLmgqnSznbJguPOZjA7CTwjpoL7LPu+ KfOAG0mZ/SvlATPYQwDY1n6YV8E28sIMn0tMbnA9ZvfEoIvgJmzyf31IDsdXZeJjti8Z JKhVJMEylOOngFGxkK9+oeIYpRoEIzhKz24BOEg5S60XGHKBXPWy4x8XxjiThdZQb76D NvhARQEu+QGWMwdp+ZueD2nysN6uhgVE/tZ4+m4yxRuLNVa3isuCh6XZKlMWYEufU6Bx C4eQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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. [23.128.96.18]) by mx.google.com with ESMTP id oa23si545887ejb.708.2020.09.24.15.08.29; Thu, 24 Sep 2020 15:08:53 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 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 S1726637AbgIXWHc (ORCPT + 99 others); Thu, 24 Sep 2020 18:07:32 -0400 Received: from mga04.intel.com ([192.55.52.120]:4453 "EHLO mga04.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726280AbgIXWHc (ORCPT ); Thu, 24 Sep 2020 18:07:32 -0400 IronPort-SDR: QBujC1q9tLgGcmMOXqkojIH1d2SY/W/Nt/Ug9J695tOHPjqMr22KtqV1tOoo7DM9g9hJJQv/fl aIDYRGf5SA7w== X-IronPort-AV: E=McAfee;i="6000,8403,9754"; a="158747644" X-IronPort-AV: E=Sophos;i="5.77,299,1596524400"; d="scan'208";a="158747644" X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga005.jf.intel.com ([10.7.209.41]) by fmsmga104.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 Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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