Received: by 2002:a05:6a10:9afc:0:0:0:0 with SMTP id t28csp1542384pxm; Thu, 3 Mar 2022 21:20:29 -0800 (PST) X-Google-Smtp-Source: ABdhPJy1VWhZIm8giETbuVeo7WGCGROB7GsCFLb6H0RQwmlxWNUAp2zN8OJ7Ek6gOAiz2sfaCe5R X-Received: by 2002:a17:906:4b11:b0:6da:b788:db6f with SMTP id y17-20020a1709064b1100b006dab788db6fmr1099192eju.586.1646371229076; Thu, 03 Mar 2022 21:20:29 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646371229; cv=none; d=google.com; s=arc-20160816; b=y5qcqlbmjqxAAQctrB6sFmzftS12+nNH9dpaznUwVgI8fJf9dE1bC63E6UqH9qPPmx lbkZfmNSpwd0QeKt77yTluuFFACSjmMny5roxBGVnMIgN5drghGXMc4AEkb16bCOLiW1 oDqFxKyJLpDgpLV1BLvZx08pAUge1QZ0St+PH3RP3ACk3dDNhtvleEZZv2Zh9S8kwTKI QwCZZ+LXOnBeH8wW/Hh6EiZGVBPk89jjUs4JNlXqtSHfmW20N26/Ms3gAZlawzdKFTT2 rbfMOkiQaGl7ycCobO1kt5t9gy47phrTtY07gVedb8/mCi7UaYmo+5jBPPZGNnQB4uel rHZg== 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=TM1/Cpe+ISk49FM5TMyCBH6AIoLnjrNVXuA+uXA5mlw=; b=SIMEFlZ+0PgxNOdKzyEcjwcdL09fdS4UClr/XWrjQcOcbhxxOo7MfId1m5m1hzh4vt kSP4/5z2z2L/yqJ8ZbfCqf/AJiQSdaOjp9qit6BniSGTJ0qXad/4IYFXjQVD15pJiaEq CLavWFWg8OaByBPiUHK6J6enjDQFFiMhChA5cp0MYw0wddEHw8tNVKuGyHO0e+zSGJq4 AgjvYWUf3IZuxF51r4wpLXaWAixyTLcufAhDM+0Z44gwyGzhm0w6XDZ2TqimoKylgmQI ICRlvUa65iS7dJ/k7ot8X5OYVUfBtJsRsBHJksAnj04s9quI6nW6Gn1DSjesFiyJ5Bz9 q89w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bdT3l8rJ; 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 jz3-20020a17090775e300b006d003fd96a9si2241908ejc.237.2022.03.03.21.20.06; Thu, 03 Mar 2022 21:20:29 -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=bdT3l8rJ; 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 S231934AbiCCXN7 (ORCPT + 99 others); Thu, 3 Mar 2022 18:13:59 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43596 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229536AbiCCXN6 (ORCPT ); Thu, 3 Mar 2022 18:13:58 -0500 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 87F92AEF33; Thu, 3 Mar 2022 15:13:11 -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 ams.source.kernel.org (Postfix) with ESMTPS id 25B3BB82702; Thu, 3 Mar 2022 23:13:10 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 72A6BC004E1; Thu, 3 Mar 2022 23:13:08 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1646349188; bh=jnUbHJnKeuwckYEvpMWc3F3NDtb/FHG6OBOmn7PIsWI=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bdT3l8rJ6JeqEF5lrrsl1NKwVjbYqE7Dao4N+tDRG6YSTm37P8E+5lVo78RZky1WR RxSii+QDHfY79q5OPqd24VH5y+RcZhQYzKwI3+t6JYoGa3ePKwMWjAliykKQf/zgXg Oo6T3MrDQV42yAXCVz9ktJN8VJx+UqGrSvgBgcvSltgK8NfYypS3pSD6ydZt/dSMyT QihU+dAXuAqjp/2XIoNrsd8BiJEE33TxDof1hBMrUO5UhQlxIdakgDoVOTw/LjNxdt EXrtSTOfnePD9qGepPtMXsq3BM60+KKhsoq71ahdpKDfmd7C9WAepyNrLO1HhtDQ5i 8OeykNSq3s64w== Date: Fri, 4 Mar 2022 01:12:28 +0200 From: Jarkko Sakkinen To: Reinette Chatre Cc: Dave Hansen , "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> <2d2d3471-78ce-9faa-daf6-138078f5ffaa@intel.com> <6f65287a-f69c-971e-be2c-929e327e7ff9@intel.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <6f65287a-f69c-971e-be2c-929e327e7ff9@intel.com> X-Spam-Status: No, score=-7.5 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, Mar 02, 2022 at 02:57:45PM -0800, Reinette Chatre wrote: > > What do you mean by "user space policy" anyway exactly? I'm sorry but I > > just don't fully understand this. > > My apologies - I just assumed that you would need no reminder about this contentious > part of SGX history. Essentially it means that, yes, the kernel could theoretically > permit any kind of access to any file/page, but some accesses are known to generally > be a bad idea - like making memory executable as well as writable - and thus there > are additional checks based on what user space permits before the kernel allows > such accesses. The device files are limited by a GID (in systemd upstream), which is a "user policy". What you want to add and why augmentation cannot be made complete before the unknown factor is added to the access control? > >>> I think the best way to move forward would be to do EAUG's explicitly with > >>> an ioctl that could also include secinfo for permissions. Then you can > >>> easily do the rest with EACCEPTCOPY inside the enclave. > >> > >> SGX_IOC_ENCLAVE_ADD_PAGES already exists and could possibly be used for > >> this purpose. It already includes SECINFO which may also be useful if > >> needing to later support EAUG of PT_SS* pages. > > > > You could also simply add SGX_IOC_ENCLAVE_AUGMENT_PAGES and call it a day. > > I could, yes. And this enables EACCEPTCOPY pattern nicely. E.g. you can implement mmap() with EAUG and then EACCEPTCOPY feeded with permissions and a zero page: 1. enclave calls back to host to do mmap() 2. host does eaug on given range and enter back to enclave. 3. enclave does eacceptcopy with given permissions and a zero page. > > I don't like this type of re-use of the existing API. > > I could proceed with SGX_IOC_ENCLAVE_AUGMENT_PAGES if there is consensus after > considering the user policy question (above) and performance trade-off (more below). Ok. If adding this would be a bottleneck it would be already persistent int "add pages", so whatever limitation there might be, it already exist. Thus, logically, that could be safely added without worrying about user policies all that much... > > > > >> The big question is whether communicating user policy after enclave initialization > >> via the SECINFO within SGX_IOC_ENCLAVE_ADD_PAGES is acceptable to all? I would > >> appreciate a confirmation on this direction considering the significant history > >> behind this topic. > > > > I have no idea because I don't know what is user space policy. > > This discussion is about some enclave usages needing RWX permissions > on dynamically added enclave pages. RWX permissions on dynamically added pages is I'm not sure if that is actually necessary, if you use EAUG-EACCEPTCOPY type of pattern. Please correct if I'm wrong. > not something that should blindly be allowed for all SGX enclaves but instead the user > needs to explicitly allow specific enclaves to have such ability. This is equivalent > to (but not the same as) what exists in Linux today with LSM. As seen in > mm/mprotect.c:do_mprotect_pkey()->security_file_mprotect() Linux is able to make > files and memory be both writable and executable, but it would only do so for those > files and memory that the LSM (which is how user policy is communicated, like SELinux) > indicates it is allowed, not blindly do so for all files and all memory. We could also potentially make LSM hooks to ioctls, if that is ever needed. And as I said earlier, EAUG ioctl does not make things any worse they might be. > >>> Putting EAUG to the #PF handler and implicitly call it just too flakky and > >>> hard to make deterministic for e.g. JIT compiler in our use case (not to > >>> mention that JIT is not possible at all because inability to do RX pages). > > I understand how SGX_IOC_ENCLAVE_AUGMENT_PAGES can be more deterministic but from > what I understand it would have a performance impact since it would require all memory > that may be needed by the enclave be pre-allocated from outside the enclave and not > just dynamically allocated from within the enclave at the time it is needed. > > Would such a performance impact be acceptable? IMHO yes because bad behaving enclave can cause the same issue anyway, and more indeterministic manner. BR, Jarkko