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 Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8F2D9C433EF for ; Mon, 14 Mar 2022 02:49:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235969AbiCNCvG (ORCPT ); Sun, 13 Mar 2022 22:51:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229645AbiCNCvE (ORCPT ); Sun, 13 Mar 2022 22:51:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CA2A7366A9; Sun, 13 Mar 2022 19:49:55 -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 656D060F73; Mon, 14 Mar 2022 02:49:55 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 25FD3C340E8; Mon, 14 Mar 2022 02:49:53 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647226194; bh=dbiYNCU9zHUF24goSbfL3UhBRIquiNGr7H1wyo9MKdI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=a8gS5CD1E0e15GzKB5EfpYlVdKyxSbEaAy+8inRwoi/vrQYwfRRh7r2SZ337arDWc jBkc83/1SM0gOUvc2VDYWD6xPVofuW2jZXG8yS6/UeeNH1ZVWuWheBEIeGEuqYq4Np HnJ0CEAhPIhT0HpNoK0oxu9YorB30rX1eKOTnUxLePQnuXpNXYXwjFoMorFmwhr8EJ EYsQXZn8ASLIBIkZc73Ir3eZbOOUTKF2gS9te/VCXG3xRu+KExKuDPSDVKhdRXiqY8 zUszLLeJTHYL5kUA+afytMeHmg6t5Ev6dnpD1367dIEg7Ot3PZ2IxgMChbTxJMEoJS 3LNsB0A63lVuA== Date: Mon, 14 Mar 2022 04:50:50 +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: Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. BR, Jarkko