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=-2.3 required=3.0 tests=HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_SANE_1 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 0CCACC11D19 for ; Thu, 20 Feb 2020 19:15:14 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id E4647222C4 for ; Thu, 20 Feb 2020 19:15:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728792AbgBTTPM (ORCPT ); Thu, 20 Feb 2020 14:15:12 -0500 Received: from mga05.intel.com ([192.55.52.43]:49172 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728111AbgBTTPM (ORCPT ); Thu, 20 Feb 2020 14:15:12 -0500 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 fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 20 Feb 2020 11:15:11 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.70,465,1574150400"; d="scan'208";a="434935036" Received: from sjchrist-coffee.jf.intel.com (HELO linux.intel.com) ([10.54.74.202]) by fmsmga005.fm.intel.com with ESMTP; 20 Feb 2020 11:15:10 -0800 Date: Thu, 20 Feb 2020 11:15:10 -0800 From: Sean Christopherson To: Andy Lutomirski Cc: Jordan Hand , Jarkko Sakkinen , LKML , X86 ML , linux-sgx@vger.kernel.org, Andrew Morton , Dave Hansen , Neil Horman , npmccallum@redhat.com, "Huang, Haitao" , Andy Shevchenko , Thomas Gleixner , "Svahn, Kai" , Borislav Petkov , Josh Triplett , "Huang, Kai" , David Rientjes , "Xing, Cedric" , puiterwijk@redhat.com, LSM List , Suresh Siddha , Haitao Huang Subject: Re: [PATCH v26 10/22] x86/sgx: Linux Enclave Driver Message-ID: <20200220191510.GF3972@linux.intel.com> References: <20200209212609.7928-1-jarkko.sakkinen@linux.intel.com> <20200209212609.7928-11-jarkko.sakkinen@linux.intel.com> <15074c16-4832-456d-dd12-af8548e46d6d@linux.microsoft.com> <20200220181345.GD3972@linux.intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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 Thu, Feb 20, 2020 at 10:51:37AM -0800, Andy Lutomirski wrote: > On Thu, Feb 20, 2020 at 10:13 AM Sean Christopherson > wrote: > > More than likely, the READ_IMPLIES_EXECUTE (RIE) crud rears its head > > because part of the enclave loader is written in assembly. Unless > > explicitly told otherwise, the linker assumes that any program with > > assembly code may need an executable stack, which leads to the RIE > > personality being set for the process. Here's a fantastic write up for > > more details: https://www.airs.com/blog/archives/518 > > > > There are essentially two paths we can take: > > > > 1) Exempt EPC pages from RIE during mmap()/mprotect(), i.e. don't add > > PROT_EXEC for enclaves. > > Seems reasonable. > > Honestly, it probably makes sense to try to exempt almost everything > from RIE. I'd be a bit surprised if RIE is actually useful for > anything other than plain anonymous pages and private file mappings. Hmm, last I looked at this I was focused on adding a generic protections manipulator, e.g. vm_ops->mprotect_adjust() and f_op->???, and I thought those options were too ugly to pursue. But if we want to start killing RIE specifically, adding a boolean flag to and f_op wouldn't be _that_ heinous, e.g. static int do_mprotect_pkey(...) { ... /* Does the application expect PROT_READ to imply PROT_EXEC */ if (rier && (vma->vm_flags & VM_MAYEXEC) && (!vma->vm_file || !vma->vm_file->f_op->no_read_implies_exec)) prot |= PROT_EXEC; } unsigned long do_mmap(...) { if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC)) if (!file || (!path_noexec(&file->f_path) && !file->f_op->no_read_implies_exec)) prot |= PROT_EXEC; }