Received: by 2002:a05:6a10:413:0:0:0:0 with SMTP id 19csp993514pxp; Wed, 16 Mar 2022 23:47:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIvqcE/ujGLn84y49PKHPbtQyOwNtwNEDSCbXwEGac58uG/O+5P7WAz2jGz0/YHnufvvHW X-Received: by 2002:a17:902:e552:b0:14f:bfec:eb2c with SMTP id n18-20020a170902e55200b0014fbfeceb2cmr3569406plf.108.1647499640542; Wed, 16 Mar 2022 23:47:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1647499640; cv=none; d=google.com; s=arc-20160816; b=SpYcIEsLeoH9ZOhmZtxkML1PS45SAyhTY2wQAanrD4oRZATIKhFvOZu4cCTacpB/N/ lNetAnfjtI2F5G58phag61q3+OQZsRlfoMxfBIV/+wBZ3U9wp4aS9rTUg2E2LLA4vhrP bKAFoCWt8xzPPwtescLdgWF26ZwejGqofGiwHakE6QSx6q0UjHuXcCha4Y/YtYgs+8fV Mtu13gmq9mmdc3sMqbPWj8rUFS2nre/PG1ulfmVDYWYIiMnx3pVYlk82FdplvKVVS4rS wsJ4cd4SsQEH8zRQNDNqkS8qUQG31l/alUJDwtleTT0q52K+PIokcdscBhu+zilGQ/XQ YQqw== 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=YX3tRVGiLJNBENzbDCijczVkKJOJmcVeHRqpqt7nFPI=; b=hIQF4orJh+S0jZxnbpmHdSy5KT2OQDBGhhLVIwOLELIiSj6C2R5QmJW4Ex0dxnn9SA YOrUG0CHOWERCiHgUWkEx/WCH6lXK2Ix3JB03SvX48qXHDz0a7PVg2SshYPLxllbik88 3wMlRElvsIJpwmkekOcyZlqUQSjvq4qzNNNQPqL79LYYDDgCPW4pH9Wp0x+NPWS9x+nu x4R1WmYoeoBPyOxPolP8CtVtRp7WPuUmmf14M/D8o/n241qK+Qv5/nni0AOJmFx1xTFk 5M6tQHbfvdn+EAcifuwI3QYwfLRvCtmlvxaS8lkkq8IFKleCPi0QMCrm6thrDgWelvtv brrw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=X7BakpF5; 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 k12-20020a170902ba8c00b0015393e34353si3438947pls.244.2022.03.16.23.47.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 23:47:20 -0700 (PDT) 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=X7BakpF5; 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 C5E0D21BC61; Wed, 16 Mar 2022 22:31:59 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229512AbiCQE5y (ORCPT + 99 others); Thu, 17 Mar 2022 00:57:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44994 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229597AbiCQE5t (ORCPT ); Thu, 17 Mar 2022 00:57:49 -0400 Received: from sin.source.kernel.org (sin.source.kernel.org [IPv6:2604:1380:40e1:4800::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 50D9B1275B1; Wed, 16 Mar 2022 21:40:00 -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 sin.source.kernel.org (Postfix) with ESMTPS id 8E569CE2296; Thu, 17 Mar 2022 04:33:45 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A4129C340E9; Thu, 17 Mar 2022 04:33:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1647491623; bh=POUoBf600nbgvc/u7XulzZAAI++wE8DaYIxOSNvmlhY=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=X7BakpF53xL/tmtjmg7eRYvWaLXE67lDtzsNXQlC9QlCMp+NdYK46fcm3BUn4Lw5K +7lVV52od1TGWXvOeFayV17PI97ExxPJ/LhnyQaj7CfI4Fm9ji9n4ddOgl5JOZXUXZ sBObzrBGSx19xOa+ltwsqPvrkW+8klO4ycfdoIFbmoKtpPTx4pJ4PjXANr0fs7tRsa N3XCeNqypg7rb20LpMgfeaXj8p6hbupYbaqVT6ZI3npr9ZgmgI6AHGx8MEtCQdyEHi OTeQzLyOr+csHogWZpK+kXO9k0cROXFq8m3Hlnhc8vOSHvbW2Nedv2weFaM6gRNVW2 hWjbOlWIaYuUg== Date: Thu, 17 Mar 2022 06:34:39 +0200 From: Jarkko Sakkinen To: Haitao Huang Cc: Reinette Chatre , "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: <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=-3.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 Mon, Mar 14, 2022 at 10:39:36AM -0500, Haitao Huang wrote: > Hi Jarkko > > On Sun, 13 Mar 2022 21:58:51 -0500, Jarkko Sakkinen > wrote: > > > 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. > > I assume up-calls here are ocalls as we call them in our implementation, > which are the calls enclave make to untrusted side via EEXIT. > > If so, can your implementation combine this two up-calls into one, then host > side just do ioctl() and mprotect to kernel? If so, would that address your > concern about extra up-calls? > > > > > > 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. > > The problem with EMODPR on #PF is that kernel needs to know what permissions > requested from enclave at the time of #PF. So enclave has to make at least > one call to kernel (again via ocall in our case, I assume up-call in your > case) to make the change. Your security scheme is broken if permissions are requested outside the enclave, i.e. the hostile environment controls the permissions. That should always come from the enclave and enclave uses EACCEPT* to validate that what was given to EMODPR, EAUG and EMODT matches its expections. Upper layer application should not never be in charge, and a broken security scheme should never be supported. If EMODPR sets unconditionally to PROT_READ, enclave is able to validate this fact and then it can use EMODPE to set appropriate permissions. BR, Jarkko