Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp2811890pxp; Mon, 14 Mar 2022 05:34:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwSSJEJTXtineJVg7zBkxtfRjp5JfFftcMGyNn9O9F/yGYNVrg3m1xE2rkV9xB83GR04cl6 X-Received: by 2002:a17:906:d54f:b0:6db:ade0:9829 with SMTP id cr15-20020a170906d54f00b006dbade09829mr11405564ejc.127.1647261292940; Mon, 14 Mar 2022 05:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647261292; cv=none; d=google.com; s=arc-20160816; b=nDGPbwCIkq8Ml7OD1grIhCgsK6udIA5AQ7Pqpl93GGVxMargr9YwleZ1tiPCiZGpNA l2jmRILGbJlF+yBEdEYakN9qncJ6LNuvqoBP5SgI1mN3SEdtOYdvFmn3mbrIJnwFXLWT wHkKbSLnjM2h+3B28dCMVsU4R1Bzp/XbE1yPdogw2uaAsVci2r0qWVWha2cQhcmishrY qJRZqGFh3X66niKYwIhCarDbosKkGpTTfjXDNPwwdinQL8ETc45wzAOPzmeMoPla8a1q sKpv1IN9w/LK4E6+z9CO4DIUUfU9ccQKxWP/INz8wtvTx/LA43eXXTIcK0cgIs/CF20K /3iQ== 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=DdAT0FzqW0zut8K1l2ITYZFcJOYNNpgs1CYQwozUif0=; b=dRYq/X6dvE1t40KxgZCgXRXO4JK3NwJ3Wj5KjWF6rabY1/YbT0O4qZBkLYw7ZPWQgo Mla+J0MhMRH+uDUsnzQh1CICxW/xiDeLmEW6XXtQ+ke/KZDuccctWM4V0MzD0sxhjZJy 5XA/L8ITZe6OsNwFyQbbUunFn4cyBy2AJuzmxrDMj67LgiS8SD8ToBo9gDfo1TAUkyCs lIIEprL7h+dEHO0L9oTX3Tp35YU0IJOIvFzjjz/6etgrvgbsXQ7WFxJcx6oEXysBgfTC 1gpfoqQs6hKyHngFAbB8Mk9/Yf4HgBPiFY3CMS1APzV8Qf4U9XoMoM07WiCShIRwjs7Q 4AIA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=afTdPDF4; 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 m6-20020a056402430600b0041699da93fesi10817933edc.186.2022.03.14.05.34.27; Mon, 14 Mar 2022 05:34:52 -0700 (PDT) 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=afTdPDF4; 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 S236024AbiCNC7I (ORCPT + 99 others); Sun, 13 Mar 2022 22:59:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38720 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230378AbiCNC7H (ORCPT ); Sun, 13 Mar 2022 22:59:07 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3886A13FAA; Sun, 13 Mar 2022 19:57:56 -0700 (PDT) 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 CE68360EF1; Mon, 14 Mar 2022 02:57:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 6115CC340E8; Mon, 14 Mar 2022 02:57:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647226675; bh=sUvovzaZJoG+yizqPaKgLqreLAazgl8KCNeOLDMDe1o=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=afTdPDF4ams4pjpHMmW8JXbJ40ptGJ51tcQL8V8uMVDUvC2FYOKP/pNPPJFDOukyY Um39fT+a54a6YIJozc/vTH3am6SBxgX+uC0ncWaUJnxJhv5XMpz9ztzBXpKpg6k3Ro SpjhDC8r4Qnsu+wlQdxbT5ekT9v134Y/dUSDVzU3PdV4oGKLafBHpKY/7I1VygLPts uGg6ahIgDq8hE3P7UaXFiaEXzhSt7z77NkX+krq09wK0FM1U1eH0S2UrVXlUiVlgF0 iR5NwLcBQ2kRfaM5m6A94ptpJmHn3AdKzQUugeUHzl+51Zp9UUKjf7yBUBcQQWK3LN NEEMqcQnWLBfw== Date: Mon, 14 Mar 2022 04:58:51 +0200 From: Jarkko Sakkinen To: Reinette Chatre Cc: Haitao Huang , "Dhanraj, Vijay" , "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" , nathaniel@profian.com Subject: Re: [PATCH V2 16/32] x86/sgx: Support restricting of enclave page permissions Message-ID: References: <4ce06608b5351f65f4e6bc6fc87c88a71215a2e7.1644274683.git.reinette.chatre@intel.com> <97565fed-dc67-bab1-28d4-c40201c9f055@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-8.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 Mon, Mar 14, 2022 at 04:50:56AM +0200, Jarkko Sakkinen wrote: > On Mon, Mar 14, 2022 at 04:49:37AM +0200, Jarkko Sakkinen wrote: > > On Fri, Mar 11, 2022 at 09:53:29AM -0800, Reinette Chatre wrote: > > > > > I saw Haitao's note that EMODPE requires "Read access permitted by enclave". > > > This motivates that EMODPR->PROT_NONE should not be allowed since it would > > > not be possible to relax permissions (run EMODPE) after that. Even so, I > > > also found in the SDM that EACCEPT has the note "Read access permitted > > > by enclave". That seems to indicate that EMODPR->PROT_NONE is not practical > > > from that perspective either since the enclave will not be able to > > > EACCEPT the change. Does that match your understanding? > > > > Yes, PROT_NONE should not be allowed. > > > > This is however the real problem. > > > > The current kernel patch set has inconsistent API and EMODPR ioctl is > > simply unacceptable. It also requires more concurrency management from > > user space run-time, which would be heck a lot easier to do in the kernel. > > > > If you really want EMODPR as ioctl, then for consistencys sake, then EAUG > > should be too. Like this when things go opposite directions, this patch set > > plain and simply will not work out. > > > > I would pick EAUG's strategy from these two as it requires half the back > > calls to host from an enclave. I.e. please combine mprotect() and EMODPR, > > either in the #PF handler or as part of mprotect(), which ever suits you > > best. > > > > I'll try demonstrate this with two examples. > > > > mmap() could go something like this() (simplified): > > 1. Execution #UD's to SYSCALL. > > 2. Host calls enclave's mmap() handler with mmap() parameters. > > 3. Enclave up-calls host's mmap(). > > 4. Loops the range with EACCEPTCOPY. > > > > mprotect() has to be done like this: > > 1. Execution #UD's to SYSCALL. > > 2. Host calls enclave's mprotect() handler. > > 3. Enclave up-calls host's mprotect(). > > 4. Enclave up-calls host's ioctl() to SGX_IOC_ENCLAVE_PERMISSIONS. > > 3. Loops the range with EACCEPT. > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ > 5. Loops the range with EACCEPT + EMODPE. > > > This is just terrible IMHO. I hope these examples bring some insight. E.g. in Enarx we have to add a special up-call (so called enarxcall in intermediate that we call sallyport, which provides shared buffer to communicate with the enclave) just for reseting the range with PROT_READ. Feel very redundant, adds ugly cruft and is completely opposite strategy to what you've chosen to do with EAUG, which is I think correct choice as far as API is concerned. BR, Jarkko