Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp1289988pxp; Thu, 10 Mar 2022 02:34:40 -0800 (PST) X-Google-Smtp-Source: ABdhPJzbiYRFe5R0Tm4NC3Wi/TvS8XeOAYn5/8BYijc9istJJZY1npZGAz6ieT+4d6VEgA16wViu X-Received: by 2002:a05:6402:31f0:b0:416:4bda:ebd4 with SMTP id dy16-20020a05640231f000b004164bdaebd4mr3552645edb.63.1646908480511; Thu, 10 Mar 2022 02:34:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646908480; cv=none; d=google.com; s=arc-20160816; b=DSetSQG3uS2QOchFwvkw8ZDeAlxZetkfd1pBn0FbGW1UffyJddcJc24gWEfKRM93ux ZYujoeffCkONY8oJ9SXz/HUXwUlT66foxGMYdP2P376pGIAmKzN71eF87y499PpGQun/ IZs/XBBW8rEqK8P0tEuSyGu9tkfvWJqp2e95QxihfA7z7st3IUsR4eIcsIaXb9miw8+f S/gd89fru2ruHdlxmzC/mnYe+8QFaWi/cbXX3+5W8ZkU+l8b+q2bvuaICIaSo1nKHE1w gHDzZ07iP0io9bstNjP+R3PLXpVNYCDbsuTehXpxNFIzsOI1+XvLyGRdGrKS5ZOSAYR3 2RuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=E3LjiSIu3sZ0dLggCqcpbRLWxjaOh1bRPK0Qbpl3JbM=; b=zi5OdUW1z+gtXuXipl1uCW0yiRRh+oCdPp5ZekRqKHTKIOP3ErFpjwtwoLMbCcRgYV +1JgaagmDbjzvA0EpS1O3BBL49f634rd+K11BJ/pa3raiwJk5Z7PvlzmS6GbeB2FAXQu 45nGfAAOPV3KJ0bO6HXRo+WqT3Sqms2bVS7STK7XDleJQfqs8PK1yj7DZFlCchJHx4pQ TZwWdySE35z8k9V4Ch/tdkHG1zQiosaplvOZfS2j7NyxPRvKiM3GQD8NP4rwgcszXsEX OduEv8S8buXRExxlRpae3msMSJsNsoHaVBCDjbQka94Lvm9TeXfACOlMhRRKlx5MoTS5 IutQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lvOi1HG4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dp22-20020a170906c15600b006db1ce8221esi3134225ejc.498.2022.03.10.02.34.15; Thu, 10 Mar 2022 02:34:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=lvOi1HG4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239612AbiCJGMj (ORCPT + 99 others); Thu, 10 Mar 2022 01:12:39 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48608 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238151AbiCJGMe (ORCPT ); Thu, 10 Mar 2022 01:12:34 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 88CCB6C1ED; Wed, 9 Mar 2022 22:11:34 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id E16106191C; Thu, 10 Mar 2022 06:11:33 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BC5DCC340E8; Thu, 10 Mar 2022 06:11:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646892693; bh=+NRsmFooFziApBCrU39ZrDWDpT82NCDcWI2bwFAfxLQ=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=lvOi1HG4F/nEVju0MUqWvgfXpukS80FBaYaZEuuwUboWQ2H8kjjD8VNNF/HXjPLJX nu4PsCTIXrQt0A/OBIs7033cPFN0Fc9f8pLWotjPiynqVHgs50DLrCd/gz3qz3eEgB PEXte7CnSpNLcrCz9Uvv9uReARgruJhMRRzSbtfDk7LoyxUUz2mtji0HsEgz97zl5j kfb/d1gI/yxFqeiwJLsEFhCkfGe66lF0JaBbvpzzviBbughdUoBmK4UJB3KRBSQiRK IYcoGSm8R5mmijav0DMrhVx064bWob7MRyOakzUqcavS3H2gCKrGMHKnmq3C6YdxT0 +aCb6LCq6SocA== Date: Thu, 10 Mar 2022 08:10:48 +0200 From: Jarkko Sakkinen To: "Dhanraj, Vijay" Cc: "Chatre, Reinette" , "dave.hansen@linux.intel.com" , "tglx@linutronix.de" , "bp@alien8.de" , "Lutomirski, Andy" , "mingo@redhat.com" , "linux-sgx@vger.kernel.org" , "x86@kernel.org" , "Christopherson,, Sean" , "Huang, Kai" , "Zhang, Cathy" , "Xing, Cedric" , "Huang, Haitao" , "Shanahan, Mark" , "hpa@zytor.com" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH V2 16/32] x86/sgx: Support restricting of enclave page permissions Message-ID: References: <4ce06608b5351f65f4e6bc6fc87c88a71215a2e7.1644274683.git.reinette.chatre@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Feb 23, 2022 at 07:21:50PM +0000, Dhanraj, Vijay wrote: > Hi All, > > Regarding the recent update of splitting the page permissions change > request into two IOCTLS (RELAX and RESTRICT), can we combine them into > one? That is, revert to how it was done in the v1 version? > > Why? Currently in Gramine (a library OS for unmodified applications, > https://gramineproject.io/) with the new proposed change, one needs to > store the page permission for each page or range of pages. And for every > request of `mmap` or `mprotect`, Gramine would have to do a lookup of the > page permissions for the request range and then call the respective IOCTL > either RESTRICT or RELAX. This seems a little overwhelming. > > Request: Instead, can we do `MODPE`, call `RESTRICT` IOCTL, and then do > an `EACCEPT` irrespective of RELAX or RESTRICT page permission request? > With this approach, we can avoid storing page permissions and simplify > the implementation. > > I understand RESTRICT IOCTL would do a `MODPR` and trigger `ETRACK` flows > to do TLB shootdowns which might not be needed for RELAX IOCTL but I am > not sure what will be the performance impact. Is there any data point to > see the performance impact? > > Thanks, > -Vijay This should get better in the next versuin. "relax" is gone. And for dynamic EAUG'd pages only VMA and EPCM permissions matter, i.e. internal vm_max_prot_bits is set to RWX. I patched the existing series eno For Enarx I'm using the following patterns. Shim mmap() handler: 1. Ask host for mmap() syscall. 2. Construct secinfo matching the protection bits. 3. For each page in the address range: EACCEPTCOPY with a zero page. Shim mprotect() handler: 1. Ask host for mprotect() syscall. 2. For each page in the address range: EACCEPT with PROT_NONE secinfo and EMODPE with the secinfo having the prot bits. Backend mprotect() handler: 1. Invoke ENCLAVE_RESTRICT_PERMISSIONS ioctl for the address range with PROT_NONE. 2. Invoke real mprotect() syscall. Not super-complicated. That is the safest way to changes permissions i.e. use EMODPR only to reset the permissions, and EMODPE as EMODP. Then the page is always either inaccessible completely or with the correct permissions. Any other ways to use EMODPR are a bit questionable. That's why I tend to think that it would be better to kernel provide only limited version of it to reset the permissions. Most of the other use will be most likely mis-use. IMHO there is only one legit pattern to use it, i.e. "least racy" pattern. I would replace SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS with SGX_IOC_ENCLAVE_RESET_PERMISSIONS that resets pages to PROT_NONE or embed this straight into mprotect(). BR, Jarkko