Received: by 2002:a05:6a10:5bc5:0:0:0:0 with SMTP id os5csp1971527pxb; Thu, 28 Oct 2021 13:38:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzb+psX9GfBXvzViGQTUno6ax0Ww6QBI0/qH3c/F7Y2gEK0lmIwIRxCOP0ngDdL3fNydj1x X-Received: by 2002:a17:90a:7d11:: with SMTP id g17mr7006044pjl.150.1635453525856; Thu, 28 Oct 2021 13:38:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1635453525; cv=none; d=google.com; s=arc-20160816; b=Lhb0d4yOqAznbkJZ7HVxbQMMi1bt1PNH8uJxdHf7Efsubr5mEzUE4hERQ9yAtoAoaO VSP/J70YbSHDW1tTy3S32UZQP4npKu739GSpL4JpA7O9Evewtn7r9cekbZfcZASO1SKQ AumdTuuu3ofms+KI3ENFhel1UiPzrVoBuK7HAGd6uzFkbElBePffjjUkZAmXLCar2+nL 6L/dUQ2n8H8uHey3XptVXohMylvg0ec2Cioc8TkCl8wkCIviSNxmV3pGRdehJ2l4A46r bK0TbYtDEsKEJ35lbVQCdXYWh3pMyQ4p9KEK1pnrNndEEef4O676iItdoFH1+vbTMkl+ h3Kg== 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=mKuCJW9fwWHFQ6t/E00AFgnFRVy8Y+OTDVmqEnj/+/Y=; b=Xxzf5I+AchOROxeww8iM74Nw7+I9uWAvKwC071iauI3Gu7HfwGRnocub4Uzz9DjcFJ BvCNKt2AMt/kkeKiz9+YWnoq5l4+xfy/1ssW+zWx59zcu6TIJnQNooEVORKIuvN1xKbb /U3PElEXVkEabe0D7XwMZ3or2vRMfbyvxOjN2dgcBwkNG06lTLG6k2XqrOmP8edBmgBM f75ITr2Fs12KWLPF1PW2Mnyq4xse/heIp8ZAGXkPpQAq/EQplx0V5EX6ixaXwy+AbZ6Q VhrZ/eC4E96UMncQUN1Ob+eNoiqcmaqrZmZW1axAyIo9SnJVCqTAez5jCRqY6q6gQvzA gwrQ== 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 nn14si5752940pjb.76.2021.10.28.13.38.33; Thu, 28 Oct 2021 13:38:45 -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 S231347AbhJ1UkD (ORCPT + 99 others); Thu, 28 Oct 2021 16:40:03 -0400 Received: from mga02.intel.com ([134.134.136.20]:2684 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230421AbhJ1Uj6 (ORCPT ); Thu, 28 Oct 2021 16:39:58 -0400 X-IronPort-AV: E=McAfee;i="6200,9189,10151"; a="217692545" X-IronPort-AV: E=Sophos;i="5.87,190,1631602800"; d="scan'208";a="217692545" Received: from orsmga008.jf.intel.com ([10.7.209.65]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 13:37:30 -0700 X-IronPort-AV: E=Sophos;i="5.87,190,1631602800"; d="scan'208";a="498562994" Received: from rchatre-ws.ostc.intel.com ([10.54.69.144]) by orsmga008-auth.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 28 Oct 2021 13:37:29 -0700 From: Reinette Chatre To: jarkko@kernel.org, linux-sgx@vger.kernel.org, shuah@kernel.org, dave.hansen@linux.intel.com Cc: seanjc@google.com, linux-kselftest@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH V2 05/15] selftests/sgx: Make data measurement for an enclave segment optional Date: Thu, 28 Oct 2021 13:37:30 -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 Acked-by: Dave Hansen Signed-off-by: Reinette Chatre --- Changes since V1: - Add signature from Dave. 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