From patchwork Wed Nov 4 13:47:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ilias Apalodimas X-Patchwork-Id: 320531 Delivered-To: patch@linaro.org Received: by 2002:a92:7b12:0:0:0:0:0 with SMTP id w18csp5452554ilc; Wed, 4 Nov 2020 05:48:10 -0800 (PST) X-Google-Smtp-Source: ABdhPJxWHkGZNCz1bxlne1chTl9ylwOV7yHXlYrkWJMHoOIOYC5hWrh2FtYcGtnQb1Fc84A++a9+ X-Received: by 2002:a17:906:3641:: with SMTP id r1mr26571403ejb.391.1604497690515; Wed, 04 Nov 2020 05:48:10 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1604497690; cv=none; d=google.com; s=arc-20160816; b=xhsJjO6WkuxggvCJUbYrgmWmjdomz3pEKYJyIbIS0qI5N+UQTsB6wGGtCERHLts28A MhNRwdAr638ZLBb8xr+WSm+30oDepJW+Ad1t/rK54WifMcIt+g7ALQZLGljdaAqWTYDf nNDFae3L9cc9HO4h4qojoccUsqFeA+jyOsAZOkjrfnT6NeEXktQX87IXMaAJAkBHeTtB 63AK+ngi2RskLjcHNKPny+3QvoF36YpjaoOO7CARhUN69yIV5DCmsA9auUKWhwJa948/ VCkB+da3USPurkj2aT0x2KVvvY22cFAGhfmi1PZt4xS1qw42U/UND8Fz/4Bp4P6ky5Si ho9w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=En350b8cSLdy3K23BMBcGspD/i8jQ6wcXbWM7X3oxWc=; b=0qc6gRoQE+9iGoFOupOtXoU4ZuUr6V40JOU7ift/1GG3GSqGn3KamHOoYpnt2R5qKo wshK65aejxJkfNKex/gT6RJrAm2XvCLhFkV869pojU06YIftDr8TfPxvBALsgPtogEdB RFu6jfPqd8bVueMj4wUeDXPrUNX395RWjSK4m9IezXB5s19NO9TcIBFrR3Q7+WoFDClx 2irR7gar8orvzhBA6wpsPMU86/r0uqNLQDd2XaQW7IUa3UR3Eka1Svxvehm56kwl8par Ar1lIXjG7HA5G6JyiWzXXMc37jvpRqgFzaWRVd+0FQ5DWHIU7Ya5TV8XEB3cj++4X+qW bgMg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aSM4PXG7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id n4si1469006ejk.692.2020.11.04.05.48.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 05:48:10 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aSM4PXG7; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4588882364; Wed, 4 Nov 2020 14:48:08 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="aSM4PXG7"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id F050B8239C; Wed, 4 Nov 2020 14:48:06 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-ej1-x643.google.com (mail-ej1-x643.google.com [IPv6:2a00:1450:4864:20::643]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id CC29A822DF for ; Wed, 4 Nov 2020 14:48:02 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=ilias.apalodimas@linaro.org Received: by mail-ej1-x643.google.com with SMTP id j24so29787771ejc.11 for ; Wed, 04 Nov 2020 05:48:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=En350b8cSLdy3K23BMBcGspD/i8jQ6wcXbWM7X3oxWc=; b=aSM4PXG7s4FM0C1Wsj9flnTkOrwR+7RG+TAjhAXxuF/YL13rhfPn5JPcXzoPgNb8st lehmo2TNEfYIHPK4+h0+TZlKQiIYFdr+Uraf20+qwquFvSaXfxsvfUwtuD2S1UVzBtbA /pMvvTClZg3uYdnvDcq7hd5Pw5U/DqZzvvIKTpiBk0NIs2ucO3LM3Tt7OSvomTCIqqzE 6FMmZv+F4AOS/tH3C1cXFC/tg/Ni8X4cK4+wEp4YODuenM9Ugs9wWAX34qcGE4BIpSH1 HppjBDpfMo0sL7ALJv1gF3v/DocK0oe+U2X0hI2F2RdY8VpmpIF8R2tigcu0jcRvv61b WaJg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=En350b8cSLdy3K23BMBcGspD/i8jQ6wcXbWM7X3oxWc=; b=sMCPYp6xAh/ddBIgFZeJc+FUxoBkhRC+izemAbnTnlPU1KXT6Le9uIRNY+XFoQRNj1 Ys+UL6ZU5KPq/CmHVy8NFUikh80djXRH9FxKu+aag7IBe1V4pY31lx1Xg/S49veArZtH HQw7TV1jOOKbFXI2kNUnlHG+8vDl7z4y3o3UT23F/xIgrsHaG+wU1kYcriejyKyVh6XI 47E1lJIRS9fNzrRNIvN81DnnjNQb1DxzeDoNajHEgZ2lJ4mUx8igtES4EEbVYPsNm1gy /gRNAN/pThDc9HUvp0nXis5b7ilN6yKmVbcKZE8U8S+b+IEaM9gZfV+DZGNOvTYK7ApU 7WKw== X-Gm-Message-State: AOAM530er1m/QKA38ZRxjDJOIViQjUm1sKztglQjJecwM9UJxY97bGXi Y1i3TL6j4NojPkwrw4vIZlzpGA== X-Received: by 2002:a17:906:b799:: with SMTP id dt25mr15721545ejb.183.1604497682264; Wed, 04 Nov 2020 05:48:02 -0800 (PST) Received: from apalos.home ([2a02:587:4615:c071:2e56:dcff:fe9a:8f06]) by smtp.gmail.com with ESMTPSA id g1sm1032708ejz.52.2020.11.04.05.48.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 04 Nov 2020 05:48:01 -0800 (PST) From: Ilias Apalodimas To: xypron.glpk@gmx.de Cc: ard.biesheuvel@arm.com, Ilias Apalodimas , Alexander Graf , Simon Glass , Miquel Raynal , Philippe Reynes , Bin Meng , Dhananjay Phadke , u-boot@lists.denx.de Subject: [PATCH 1/2] tpm: Make response length of tpm2_get_capability() configurable Date: Wed, 4 Nov 2020 15:47:46 +0200 Message-Id: <20201104134748.810291-1-ilias.apalodimas@linaro.org> X-Mailer: git-send-email 2.29.2 MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.102.3 at phobos.denx.de X-Virus-Status: Clean A following patch introduces EFI_TCG2_PROTOCOL. One of the functions of that protocol is GetCapability(). In order to parse device capabilities we need to access a u32 before the properties which the current implementation ignores while reading device properties. So let's make the response length configurable and prepare the functions for EFI_TCG2_PROTOCOL. Signed-off-by: Ilias Apalodimas --- cmd/tpm-v2.c | 2 +- include/tpm-v2.h | 12 +++++++----- lib/tpm-v2.c | 10 +++++++--- 3 files changed, 15 insertions(+), 9 deletions(-) -- 2.29.2 diff --git a/cmd/tpm-v2.c b/cmd/tpm-v2.c index e6742656f578..c2df1c34043a 100644 --- a/cmd/tpm-v2.c +++ b/cmd/tpm-v2.c @@ -183,7 +183,7 @@ static int do_tpm_get_capability(struct cmd_tbl *cmdtp, int flag, int argc, data = map_sysmem(simple_strtoul(argv[3], NULL, 0), 0); count = simple_strtoul(argv[4], NULL, 0); - rc = tpm2_get_capability(dev, capability, property, data, count); + rc = tpm2_get_capability(dev, capability, property, data, count, false); if (rc) goto unmap_data; diff --git a/include/tpm-v2.h b/include/tpm-v2.h index f6c045d35480..ee74028ca83b 100644 --- a/include/tpm-v2.h +++ b/include/tpm-v2.h @@ -257,15 +257,17 @@ u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, * to query property index that is 4-byte wide. * * @dev TPM device - * @capability Partition of capabilities - * @property Further definition of capability, limited to be 4 bytes wide - * @buf Output buffer for capability information - * @prop_count Size of output buffer + * @capability Partition of capabilities + * @property Further definition of capability, limited to be 4 bytes + * wide + * @buf Output buffer for capability information + * @prop_count Size of output buffer + * @get_count Include tpmu property count * * @return code of the operation */ u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property, - void *buf, size_t prop_count); + void *buf, size_t prop_count, bool get_count); /** * Issue a TPM2_DictionaryAttackLockReset command. diff --git a/lib/tpm-v2.c b/lib/tpm-v2.c index a4c352e3ef75..b58c1057995b 100644 --- a/lib/tpm-v2.c +++ b/lib/tpm-v2.c @@ -161,7 +161,7 @@ u32 tpm2_pcr_read(struct udevice *dev, u32 idx, unsigned int idx_min_sz, } u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property, - void *buf, size_t prop_count) + void *buf, size_t prop_count, bool get_count) { u8 command_v2[COMMAND_BUFFER_SIZE] = { tpm_u16(TPM2_ST_NO_SESSIONS), /* TAG */ @@ -181,13 +181,17 @@ u32 tpm2_get_capability(struct udevice *dev, u32 capability, u32 property, if (ret) return ret; + /* When reading PCR properties we need the count */ + properties_off = sizeof(u16) + sizeof(u32) + sizeof(u32) + + sizeof(u8) + sizeof(u32); /* * In the response buffer, the properties are located after the: * tag (u16), response size (u32), response code (u32), * YES/NO flag (u8), TPM_CAP (u32) and TPMU_CAPABILITIES (u32). */ - properties_off = sizeof(u16) + sizeof(u32) + sizeof(u32) + - sizeof(u8) + sizeof(u32) + sizeof(u32); + if (!get_count) + properties_off += sizeof(u32); + memcpy(buf, &response[properties_off], response_len - properties_off); return 0;