Received: by 2002:a05:6a11:4021:0:0:0:0 with SMTP id ky33csp799400pxb; Wed, 15 Sep 2021 13:33:19 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyP0xbNA/NkPpoXqaIvvCcRMxLu8PUbV6LCkQzQLbMKe0b+pNW8ldet7UpTyYs5cXP3OaYJ X-Received: by 2002:aa7:db17:: with SMTP id t23mr2126139eds.387.1631737998966; Wed, 15 Sep 2021 13:33:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631737998; cv=none; d=google.com; s=arc-20160816; b=xywRUgUSr8lgNWgBC3nREgcrR1bJGTqHjcY9nf0/jW14F1IBJAL6pWKVW4KL5gy5Je 8vEAqm+WZwYpqqohrRIF92LsT2xY33nsvm7Zjzt1j4pWDQilzOOAUTSPIFyao1OZ7ph7 a2SYIcz9uiFj1LyOXhbH0WFdkIH4t5fu5l+H10yEAqjtIPMaXcpGU6IoBTJKakHsyHnc PCQsSlKVLCEVACmdN+axvWJ5eg9WSsij4gpC4A1ujLBjANsGJoVnk8GxvjAxAFlHf/h9 FVbeChwEWVBlAbOqy2SOkfiGxV7TGxoOQa/kyi+pVbG33GI0f31elVA0fyOP8zwhGDOt i2PA== 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 :references:in-reply-to:message-id:date:subject:cc:to:from; bh=Iw0Jb1AEaZgE7GFtGQ+3P6Q31PLwN1dohoIhLPP609g=; b=E0VvbYsbrENTxrzv6tYFVNO/iMKseIUnBXqwhqrTBubgz372GG/6+Zufg9CLjNr6X0 Qr6lKGWrUdAKiOSpBy4U9qIMlSCbECsbD6K0aeVOrDjs8xqCblHB4LiyzzTKoQtiKyQO /ndsWWraDWNFY++417/hW99smLk+ftFCovK/n+CkhkB4qa+OGa6V/kQxMhfy5Nquu8kH QQPBlBZ+GxGhV9Bq/bUawcsR0I8SkMZFVwkqS+51t5BmbKW8oTue5VdbZVoIXF0l0L6t lKlFyRhSP5S7zzC8Z//1hM50cGFZpor8JsKyhFxBPHakL/7Eau55vK85tKPRe4cwnQQ2 3yrw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hr6si1517180ejc.711.2021.09.15.13.32.55; Wed, 15 Sep 2021 13:33:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232129AbhIOUcr (ORCPT + 99 others); Wed, 15 Sep 2021 16:32:47 -0400 Received: from mga07.intel.com ([134.134.136.100]:13811 "EHLO mga07.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231863AbhIOUce (ORCPT ); Wed, 15 Sep 2021 16:32:34 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10108"; a="286109362" X-IronPort-AV: E=Sophos;i="5.85,296,1624345200"; d="scan'208";a="286109362" Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga105.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 13:31:14 -0700 X-IronPort-AV: E=Sophos;i="5.85,296,1624345200"; d="scan'208";a="545092776" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by fmsmga003-auth.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 15 Sep 2021 13:31:13 -0700 From: Reinette Chatre To: linux-sgx@vger.kernel.org, jarkko@kernel.org, shuah@kernel.org Cc: seanjc@google.com, bp@alien8.de, dave.hansen@linux.intel.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 04/14] selftests/sgx: Make data measurement for an enclave segment optional Date: Wed, 15 Sep 2021 13:30:54 -0700 Message-Id: X-Mailer: git-send-email 2.25.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jarkko Sakkinen For a heap makes sense to leave its contents "unmeasured" in the SGX enclave build process, meaning that they won't contribute to the cryptographic signature (a RSA-3072 signed SHA56 hash) of the enclave. Enclaves are signed blobs where the signature is calculated both from page data and also from "structural properties" of the pages. For instance a page offset of *every* page added to the enclave is hashed. For data, this is optional, not least because hashing a page has a significant contribution to the enclave load time. Thus, where there is no reason to hash, do not. The SGX ioctl interface supports this with SGX_PAGE_MEASURE flag. Only when the flag is *set*, data is measured. Add seg->measure boolean flag to struct encl_segment. Only when the flag is set, include the segment data to the signature (represented by SIGSTRUCT architectural structure). Signed-off-by: Jarkko Sakkinen Signed-off-by: Reinette Chatre --- tools/testing/selftests/sgx/load.c | 6 +++++- tools/testing/selftests/sgx/main.h | 1 + tools/testing/selftests/sgx/sigstruct.c | 6 ++++-- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/tools/testing/selftests/sgx/load.c b/tools/testing/selftests/sgx/load.c index 5605474aab73..f1be78984c50 100644 --- a/tools/testing/selftests/sgx/load.c +++ b/tools/testing/selftests/sgx/load.c @@ -111,7 +111,10 @@ static bool encl_ioc_add_pages(struct encl *encl, struct encl_segment *seg) ioc.offset = seg->offset; ioc.length = seg->size; ioc.secinfo = (unsigned long)&secinfo; - ioc.flags = SGX_PAGE_MEASURE; + if (seg->measure) + ioc.flags = SGX_PAGE_MEASURE; + else + ioc.flags = 0; rc = ioctl(encl->fd, SGX_IOC_ENCLAVE_ADD_PAGES, &ioc); if (rc < 0) { @@ -230,6 +233,7 @@ bool encl_load(const char *path, struct encl *encl) seg->offset = (phdr->p_offset & PAGE_MASK) - src_offset; seg->size = (phdr->p_filesz + PAGE_SIZE - 1) & PAGE_MASK; seg->src = encl->src + seg->offset; + seg->measure = true; j++; } diff --git a/tools/testing/selftests/sgx/main.h b/tools/testing/selftests/sgx/main.h index 452d11dc4889..aebc69e7cdc8 100644 --- a/tools/testing/selftests/sgx/main.h +++ b/tools/testing/selftests/sgx/main.h @@ -12,6 +12,7 @@ struct encl_segment { size_t size; unsigned int prot; unsigned int flags; + bool measure; }; struct encl { diff --git a/tools/testing/selftests/sgx/sigstruct.c b/tools/testing/selftests/sgx/sigstruct.c index 202a96fd81bf..50c5ab1aa6fa 100644 --- a/tools/testing/selftests/sgx/sigstruct.c +++ b/tools/testing/selftests/sgx/sigstruct.c @@ -296,8 +296,10 @@ static bool mrenclave_segment(EVP_MD_CTX *ctx, struct encl *encl, if (!mrenclave_eadd(ctx, seg->offset + offset, seg->flags)) return false; - if (!mrenclave_eextend(ctx, seg->offset + offset, seg->src + offset)) - return false; + if (seg->measure) { + if (!mrenclave_eextend(ctx, seg->offset + offset, seg->src + offset)) + return false; + } } return true; -- 2.25.1