From patchwork Fri Aug 23 02:00:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Christopherson X-Patchwork-Id: 11110423 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 606A513A4 for ; Fri, 23 Aug 2019 02:00:04 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 3DF4D23404 for ; Fri, 23 Aug 2019 02:00:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388264AbfHWCAE (ORCPT ); Thu, 22 Aug 2019 22:00:04 -0400 Received: from mga05.intel.com ([192.55.52.43]:25633 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1733086AbfHWCAD (ORCPT ); Thu, 22 Aug 2019 22:00:03 -0400 X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by fmsmga105.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 22 Aug 2019 19:00:04 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.64,419,1559545200"; d="scan'208";a="263047994" Received: from sjchrist-coffee.jf.intel.com ([10.54.74.41]) by orsmga001.jf.intel.com with ESMTP; 22 Aug 2019 19:00:03 -0700 From: Sean Christopherson To: Jarkko Sakkinen Cc: linux-sgx@vger.kernel.org Subject: [PATCH] x86/sgx: Fix ELDU MAC failures Date: Thu, 22 Aug 2019 19:00:02 -0700 Message-Id: <20190823020002.25550-1-sean.j.christopherson@intel.com> X-Mailer: git-send-email 2.22.0 MIME-Version: 1.0 Sender: linux-sgx-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-sgx@vger.kernel.org Revert a change that directly propagates the page type from SECINFO into encl_page->desc. encl_page->desc is a packed value, jamming the SECINFO page_type sets bits that are intended for other uses. Specifically, bits 11:3 are used to store the VA offset when a page is swapped out and are available for other uses when the page is resident in the EPC. To allow overloading bits 11:3, the VA offset is cleared at ELDU and so is not explicitly cleared at EWB, e.g. the VA offset is OR'd into encl_page->desc. As a result, a subsequent ELDU gets a MAC failure due to loading the wrong VA offset. Signed-off-by: Sean Christopherson --- arch/x86/kernel/cpu/sgx/driver/ioctl.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/arch/x86/kernel/cpu/sgx/driver/ioctl.c b/arch/x86/kernel/cpu/sgx/driver/ioctl.c index 85e36e530baf..355ce967a77f 100644 --- a/arch/x86/kernel/cpu/sgx/driver/ioctl.c +++ b/arch/x86/kernel/cpu/sgx/driver/ioctl.c @@ -140,7 +140,8 @@ static struct sgx_encl_page *sgx_encl_page_alloc(struct sgx_encl *encl, return ERR_PTR(-ENOMEM); encl_page->desc = addr; - encl_page->desc |= page_type; + if (page_type == SGX_SECINFO_TCS) + encl_page->desc |= SGX_ENCL_PAGE_TCS; encl_page->encl = encl; /* Calculate maximum of the VM flags for the page. */