Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp698961pxp; Fri, 11 Mar 2022 12:42:52 -0800 (PST) X-Google-Smtp-Source: ABdhPJwBOG2BGNCKHxWrq98l+n8ZyIDY84D/U8mgOMgIdB5RjJCHmyE193DhQVQVvKoFYa6uvJMJ X-Received: by 2002:a17:90a:dc18:b0:1bf:50c7:a4fa with SMTP id i24-20020a17090adc1800b001bf50c7a4famr12478936pjv.187.1647031371850; Fri, 11 Mar 2022 12:42:51 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1647031371; cv=none; d=google.com; s=arc-20160816; b=Srpw5TzjZ/yEjUZBw2pdwR3qU7n+oIokMXdOueVgnI+jeFYdMA9LWF7PEIBf5n7niD zzdR4ih3AJN7hwsX8s0XTK1GAVuYJZmjGSQdqVvGHWdkb6pftdJLV1hCNk90rJj/cCYs hqv84alxkRjvibYtJC4/HxNZubZk7pDfUrhtV7ULHFP4yvnCIpPg1TAD/xXll3f3BJhL WCzNFwmH1MhVaDbyTwMqaXie6jpmzBcb+l1uc6N/OA8nCpe7riXijvDeWZEWvvR7cYue 0+kVfhKETUV+H5+rPgzqasdrTwfIRR6WiazFaLDCAgd5U5jXf7DuTz/ZuzGTLwU5N+Kj IU3A== 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=hP/BDhzaTVPw69xOzsnYne46qZ7JymdYqMxmOB7cSho=; b=xuWIlXRbGXA8/Oxc1BlpKm1YGYGces/KMkxPDTkEe12pstfhUK/EVqtGEjLztxbyL4 Yo7oLKyQt986xQjXdN0FrSwu9ReG3LdzGOdEz9dgGn8gABXeGWCCcNJOIKXqQZWbgaRO GdzmCB+TZdoJlQtUzfMheNGxcYNi6weyZVfncdIws7xqWQ2wqs6vTV2UtM9TXFhkhuE8 AY+KoqPteQWHR9kfqXfaJlC+D46aD0jN3njHXU+8cSqRlAR3LBGoePWiy7Wx+PGw/ImI +gw+eFht/3zPX2F9QdKSePamWQlad6fIpFxz3SP7KsmEM+USTnvO5tV2VlOP5UcJi/Ar Okzg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EXBUsqoQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 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 lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id w6-20020a639346000000b003739e9e86c6si9199416pgm.877.2022.03.11.12.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Mar 2022 12:42:51 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=EXBUsqoQ; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 36C561D9838; Fri, 11 Mar 2022 12:39:51 -0800 (PST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350793AbiCKSNL (ORCPT + 99 others); Fri, 11 Mar 2022 13:13:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48690 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231271AbiCKSNK (ORCPT ); Fri, 11 Mar 2022 13:13:10 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DB6FF1D3DAA; Fri, 11 Mar 2022 10:12:06 -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 6718561E84; Fri, 11 Mar 2022 18:12:06 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 478CFC340EC; Fri, 11 Mar 2022 18:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647022325; bh=uYvE7bQA3vVCKRU/cREAI+1LDFVSuyI3rV9XY6TDwYk=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=EXBUsqoQStTGw+FtuP8pLWZUeAZkBCT85ZilWvbaaqw1nAmSs7q71PHbLdPzfefEd 162cp/8BaMKh5084i34Out4wfkl3twkNq1kA78HvIHE9OyQEIqXDfWDBMDboimf8g3 5iCDdpIpzx9Plbf3Fpnou9cajRlkMd6MoOb8PTohiRqhPYUJycWPG5samG+cJZdt88 q/ZNSh3lm9+Ek/IX0ZLZ84P6QQ1Ha5Fs9l28vT/ki441Oy2b/Y4Km4e4VU8ho1ax/E 2zOHzrv2dYfhsoMpwkWc55TCurCzUlGGLs8i4CaxsnprJtuvBiyiP9ZjGXtZ9Xh5Py bbXGHrcm9zlsw== Date: Fri, 11 Mar 2022 20:11:19 +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" 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: <97565fed-dc67-bab1-28d4-c40201c9f055@intel.com> X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,MAILING_LIST_MULTI, RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=unavailable 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 Fri, Mar 11, 2022 at 09:53:29AM -0800, Reinette Chatre wrote: > I do not believe that you encountered the #GP documented above because that > check is already present in the current implementation of > SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS: > > sgx_ioc_enclave_restrict_permissions()->sgx_perm_from_user_secinfo(): > if ((perm & SGX_SECINFO_W) && !(perm & SGX_SECINFO_R)) > return -EINVAL; > > It does return EINVAL which is the catch-all error code used to represent > invalid input from user space. I am not convinced that EACCES should be used > instead though, EACCES means "Permission denied", which is not the case here. > The case here is just an invalid request. > > It currently does not prevent the user from setting PROT_NONE though, which > EMODPR does seem to allow. > > 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? > > I will add the check for R in SGX_IOC_ENCLAVE_RESTRICT_PERMISSIONS at least. Yes, I think we are in the same line with this. But there is another thing. As EAUG is taken care by the page handler so should EMODPR. It makes the developer experience whole a lot easier when you don't have to back call to host and ask it to execute EMODPR for the range. It's also a huge incosistency in this patch set that they are handled differently. And it creates a concurrency case for user space that is complicated to say the least, i.e. divided work between host and enclave implementation to execute EMODPR is a nightmare scenario. On the other hand this is trivial to sort out in kernel. So what it means that, in one way or antoher, mprotect() needs to be the melting point for both. This can be called mandatory requirement, however this patch set it done, not least because of managing concurrency between kernel and user space. You can get that done by these steps: 1. Unmap PTE's in mprotect() flow. 2. In #PF handler, EMODPR with R set. This clear API for enclave developer because you know in what state pages are after mprotect(), and what you need to still do to them. Only the syscall needs to be them performed by the host side. BR, Jarkko