Received: by 2002:a5d:9c59:0:0:0:0:0 with SMTP id 25csp89803iof; Sun, 5 Jun 2022 22:02:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz1UEbz/bf3g4ZfRnd9exWcVAwcP7z2zQe8h0JQkre2cEIV2op87THzVBAiX+rD9jZ3NFpE X-Received: by 2002:a17:902:c951:b0:163:efad:406d with SMTP id i17-20020a170902c95100b00163efad406dmr22460413pla.55.1654491778286; Sun, 05 Jun 2022 22:02:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654491778; cv=none; d=google.com; s=arc-20160816; b=oW4TLi1v8yZpfFCFIuiev/84SR1BmAZTGaavQGmkdKVx8eqooFl1MQqZhopTbrMpk4 UxUNxqHMS2smVsWu0ygGmdD76Nkz6PtiTGcte8Gy1vDWUgdjNCk5O/JiwF9rxQizU3hJ ecbR/mUVF1vKG2tR/z/FaCiHOKGX8uR0/S9AUXmg+Fn/xi0hO6zaTvTH/Pyg6pgYuNIw gDxfvQEzJSGlHIP+1u8MHfCMXY110iDNIxjTfx44w9+1sKZMgUCYesGzxGDyBlhlshu4 VukTrzeB9QOw6gGB2xYgcxE/iptmuONQ5Oax0gvRg5RW0m7Awa46wnK+YbC3AjTYApwJ te+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xyZmblveHR8CmSisxe+22fIeNg1lSDhmflGHhJilDlE=; b=AWCZ4q0XtfzWikcVp5F8P6hdBCjOSX6THIGNOWT2tL7JmgzAysUBL/zFuFdwYUy7Oy YD+rwoDQsao5V+j68k6TEX+WA2ObyRSyGGidY6QzaZIrmsMMyUU1skug6QdFABufdSGZ tajnWQl47e9HDXHKqbgTW5PdVUPeZkHLiTtWVTxkcbbRd0LlX6nPCi6baiAMDjtWVXxx r6/K2iYV0lSq4mbfWVCIV+/U9P7QMLjUK/Uow00WjefLjasB/4rNmas3dGL2ez/cEv5G HUrsZPOC80RmoY6oFvlpr8iR7OzbeXW+EsymhLltPgx7LwkdJVHO5rZKBwrhp+w8icbU dWyw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=gphYyYLt; 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=linuxfoundation.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id s76-20020a632c4f000000b003fbe1c24cd1si19139152pgs.684.2022.06.05.22.02.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 05 Jun 2022 22:02:58 -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=@linuxfoundation.org header.s=korg header.b=gphYyYLt; 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=linuxfoundation.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EFC89ED8FA; Sun, 5 Jun 2022 21:11:12 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S244731AbiFCSB4 (ORCPT + 99 others); Fri, 3 Jun 2022 14:01:56 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58150 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347243AbiFCRwK (ORCPT ); Fri, 3 Jun 2022 13:52:10 -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 2FF9565B0; Fri, 3 Jun 2022 10:51:08 -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 C09C560EE9; Fri, 3 Jun 2022 17:51:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CD0F1C385A9; Fri, 3 Jun 2022 17:51:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1654278667; bh=DdcTsahpMA3mopHeABHUdvpDhh4i1FgDJdxIWWBmhHc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=gphYyYLtbjedEeryDiSVeIGtXqFf2Jyi/7oA3Bk9ljne8tttOjOw1R4je7C4seUdF 4Mw3CHsZlyQ6p7GYZ4aXlrIYQqu60RWo+xz796qG9BAW7swYts1MKqmc+VSbL9Dj8L au/RVVUhhdpEb7JuKMXdi9eaV2qIrE0nm3D53E9E= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Dave Hansen , Reinette Chatre , Jarkko Sakkinen , Haitao Huang Subject: [PATCH 5.15 54/66] x86/sgx: Ensure no data in PCMD page after truncate Date: Fri, 3 Jun 2022 19:43:34 +0200 Message-Id: <20220603173822.222435530@linuxfoundation.org> X-Mailer: git-send-email 2.36.1 In-Reply-To: <20220603173820.663747061@linuxfoundation.org> References: <20220603173820.663747061@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, 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 From: Reinette Chatre commit e3a3bbe3e99de73043a1d32d36cf4d211dc58c7e upstream. A PCMD (Paging Crypto MetaData) page contains the PCMD structures of enclave pages that have been encrypted and moved to the shmem backing store. When all enclave pages sharing a PCMD page are loaded in the enclave, there is no need for the PCMD page and it can be truncated from the backing store. A few issues appeared around the truncation of PCMD pages. The known issues have been addressed but the PCMD handling code could be made more robust by loudly complaining if any new issue appears in this area. Add a check that will complain with a warning if the PCMD page is not actually empty after it has been truncated. There should never be data in the PCMD page at this point since it is was just checked to be empty and truncated with enclave mutex held and is updated with the enclave mutex held. Suggested-by: Dave Hansen Signed-off-by: Reinette Chatre Signed-off-by: Dave Hansen Reviewed-by: Jarkko Sakkinen Tested-by: Haitao Huang Link: https://lkml.kernel.org/r/6495120fed43fafc1496d09dd23df922b9a32709.1652389823.git.reinette.chatre@intel.com Signed-off-by: Greg Kroah-Hartman --- arch/x86/kernel/cpu/sgx/encl.c | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) --- a/arch/x86/kernel/cpu/sgx/encl.c +++ b/arch/x86/kernel/cpu/sgx/encl.c @@ -187,12 +187,20 @@ static int __sgx_encl_eldu(struct sgx_en kunmap_atomic(pcmd_page); kunmap_atomic((void *)(unsigned long)pginfo.contents); + get_page(b.pcmd); sgx_encl_put_backing(&b); sgx_encl_truncate_backing_page(encl, page_index); - if (pcmd_page_empty && !reclaimer_writing_to_pcmd(encl, pcmd_first_page)) + if (pcmd_page_empty && !reclaimer_writing_to_pcmd(encl, pcmd_first_page)) { sgx_encl_truncate_backing_page(encl, PFN_DOWN(page_pcmd_off)); + pcmd_page = kmap_atomic(b.pcmd); + if (memchr_inv(pcmd_page, 0, PAGE_SIZE)) + pr_warn("PCMD page not empty after truncate.\n"); + kunmap_atomic(pcmd_page); + } + + put_page(b.pcmd); return ret; }