From patchwork Sat Oct 18 08:40:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Glass X-Patchwork-Id: 605 Return-Path: X-Original-To: u-boot-concept@u-boot.org Delivered-To: u-boot-concept@u-boot.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760776915; bh=xgjO2Bs8Yy/DAc/2bTt10AdRkkumZnAa7bjxMtE0WfA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CyjisZZwK0dODx2O6wUTqbOxnR4s9PWAeYl5rJL6poCeeiSMOlZkC6S8kVnInguWi rr20BxoBCHcMcH9jhmYsrws8/OuLPjs0k+ogCZeXuQ0t7pp/32mr7OMQFdY6Vdr9Ru BH3eLdFdgjWf7QEnrF5MFcy7gmk2ejbGSbC4E2EFrVhAldAg+6NkDQcAzex+w2w18X yY9DLKtWnX4qfBp/KvDZFy/IRr8Faa/7JLnA/QUbStJai8eSWZ9Kkxh8mo2tgtsm22 JgYdun4O/VToHnukBJMOuj4i/zY0ZpyIrnTEtNhFV+FhQlTWzj7Pic1Ur1ycHVKlqu NaW2O9n9mKBAw== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 711AE68109 for ; Sat, 18 Oct 2025 02:41:55 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10024) with ESMTP id UmN286uvgp3a for ; Sat, 18 Oct 2025 02:41:55 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760776915; bh=xgjO2Bs8Yy/DAc/2bTt10AdRkkumZnAa7bjxMtE0WfA=; h=From:To:Date:In-Reply-To:References:CC:Subject:List-Id: List-Archive:List-Help:List-Owner:List-Post:List-Subscribe: List-Unsubscribe:From; b=CyjisZZwK0dODx2O6wUTqbOxnR4s9PWAeYl5rJL6poCeeiSMOlZkC6S8kVnInguWi rr20BxoBCHcMcH9jhmYsrws8/OuLPjs0k+ogCZeXuQ0t7pp/32mr7OMQFdY6Vdr9Ru BH3eLdFdgjWf7QEnrF5MFcy7gmk2ejbGSbC4E2EFrVhAldAg+6NkDQcAzex+w2w18X yY9DLKtWnX4qfBp/KvDZFy/IRr8Faa/7JLnA/QUbStJai8eSWZ9Kkxh8mo2tgtsm22 JgYdun4O/VToHnukBJMOuj4i/zY0ZpyIrnTEtNhFV+FhQlTWzj7Pic1Ur1ycHVKlqu NaW2O9n9mKBAw== Received: from mail.u-boot.org (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 5BA0B68188 for ; Sat, 18 Oct 2025 02:41:55 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760776913; bh=xypRfof6E5gjHyKiVXjUb1HTqOMq98sJNmMFvsPPHkA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=N+BnMckmdPXCwV1b6aoegOjMJn9wfY5NhA7pSCsEjxxOsqzZH9xzM3Q4ZrcE8hLKs A542jOR388/8nq69R40+jtGJIaLLR/oQJ5w04lvPdugMdgK8kNRGjTHE491C8Gd1FG MsC1KPEwcE7MyFyKv5AisqBdb0t/jlAKTztpF7tRAForJbDuPWUetFXs3DaUlu5TUl 9W87k2f8ajh++Ex/RxO+v//RVmMoL2X+Ntyh5DAe/CSgG0mTMIOECbL2/RToszBluC wu7CZ+m3AY00EyA21viNVBCGtHFlvi8tclESaxeLH2rogkhTlWuWjcUR/2fzxLSw0J 61JrOWradZdpQ== Received: from localhost (localhost [127.0.0.1]) by mail.u-boot.org (Postfix) with ESMTP id 3DB9168188; Sat, 18 Oct 2025 02:41:53 -0600 (MDT) X-Virus-Scanned: Debian amavis at Received: from mail.u-boot.org ([127.0.0.1]) by localhost (mail.u-boot.org [127.0.0.1]) (amavis, port 10026) with ESMTP id vb3gafJYweCd; Sat, 18 Oct 2025 02:41:53 -0600 (MDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=u-boot.org; s=default; t=1760776906; bh=22RS5jMcwDshY1LDguOhRyRCIaEq/UZ+thdjTUBbj7A=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UqbRQPmEwhNbkLYoH/I+8DPbTh6hdr1AL7hI0hUgzes17vWkETn6smfAKn5oYx9lw ywsBolXv/OdlAMDk8HUXBt9KlUGY0Wwh2WeuyQzstLlNdbcoz3gtSKX35h9rS9u8ky N6ALvbm35+dy47JCWuyeqdi6ADs5OB28aG20XGxi0UwCDuZy7tnPqR8j/MucGKIzn0 ZgiZWPxlFu+AA1roFOmDXSq4Lkta3D4Tsg0gEnGyBO+HB/8PaE/rDzVMMqfhMgyxxI A2IK/dLKifahpRhvmWBXtgDr4Bm/pYj6ZoBF360hSzpLHjpkpqYVEc9Z0+PtCTStip a0vHqRPKO178A== Received: from u-boot.org (unknown [73.34.74.121]) by mail.u-boot.org (Postfix) with ESMTPSA id BE25068109; Sat, 18 Oct 2025 02:41:45 -0600 (MDT) From: Simon Glass To: U-Boot Concept Date: Sat, 18 Oct 2025 02:40:50 -0600 Message-ID: <20251018084117.1798704-6-sjg@u-boot.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20251018084117.1798704-1-sjg@u-boot.org> References: <20251018084117.1798704-1-sjg@u-boot.org> MIME-Version: 1.0 Message-ID-Hash: BXBFDYQHR73NSN3OZPL2FIWKMUTZ72RS X-Message-ID-Hash: BXBFDYQHR73NSN3OZPL2FIWKMUTZ72RS X-MailFrom: sjg@u-boot.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; loop; banned-address; emergency; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: Simon Glass X-Mailman-Version: 3.3.10 Precedence: list Subject: [Concept] [PATCH 05/24] tpm: Correct address handling in tcg2_platform_get_log() List-Id: Discussion and patches related to U-Boot Concept Archived-At: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: From: Simon Glass This function assumes that an address is the same as a pointer. Use map_sysmem() to fix this, which crashes on sandbox. Rename the parameter from addr to ptr, to avoid further confusion. Signed-off-by: Simon Glass --- include/tpm_tcg2.h | 4 ++-- lib/tpm_tcg2.c | 21 +++++++++++---------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/include/tpm_tcg2.h b/include/tpm_tcg2.h index 189a93ee840..e305bc29a95 100644 --- a/include/tpm_tcg2.h +++ b/include/tpm_tcg2.h @@ -313,12 +313,12 @@ void tcg2_measurement_term(struct udevice *dev, struct tcg2_event_log *elog, * Get the platform event log address and size. * * @dev TPM device - * @addr Address of the log + * @addr Pointer to the log * @size Size of the log * * Return: zero on success, negative errno otherwise */ -int tcg2_platform_get_log(struct udevice *dev, void **addr, u32 *size); +int tcg2_platform_get_log(struct udevice *dev, void **ptrp, u32 *sizep); /** * Get the first TPM2 device found. diff --git a/lib/tpm_tcg2.c b/lib/tpm_tcg2.c index 364f7287438..bcd3423d923 100644 --- a/lib/tpm_tcg2.c +++ b/lib/tpm_tcg2.c @@ -671,7 +671,7 @@ void tcg2_measurement_term(struct udevice *dev, struct tcg2_event_log *elog, unmap_physmem(elog->log, MAP_NOCACHE); } -__weak int tcg2_platform_get_log(struct udevice *dev, void **addr, u32 *size) +__weak int tcg2_platform_get_log(struct udevice *dev, void **ptrp, u32 *sizep) { const __be32 *addr_prop = NULL; const __be32 *size_prop = NULL; @@ -680,13 +680,14 @@ __weak int tcg2_platform_get_log(struct udevice *dev, void **addr, u32 *size) struct ofnode_phandle_args args; phys_addr_t a; fdt_size_t s; + void *ptr; + int size; - *addr = NULL; - *size = 0; + ptr = bloblist_get_blob(BLOBLISTT_TPM_EVLOG, &size); + if (ptr && size) { + ulong addr = map_to_sysmem(ptr); - *addr = bloblist_get_blob(BLOBLISTT_TPM_EVLOG, size); - if (*addr && *size) { - *addr = map_physmem((uintptr_t)(*addr), *size, MAP_NOCACHE); + *ptrp = map_physmem(addr, size, MAP_NOCACHE); return 0; } @@ -714,8 +715,8 @@ __weak int tcg2_platform_get_log(struct udevice *dev, void **addr, u32 *size) u64 a = of_read_number(addr_prop, asize / sizeof(__be32)); u64 s = of_read_number(size_prop, ssize / sizeof(__be32)); - *addr = map_physmem(a, s, MAP_NOCACHE); - *size = (u32)s; + *ptrp = map_physmem(a, s, MAP_NOCACHE); + *sizep = (u32)s; return 0; } @@ -727,8 +728,8 @@ __weak int tcg2_platform_get_log(struct udevice *dev, void **addr, u32 *size) if (a == FDT_ADDR_T_NONE) return -ENOMEM; - *addr = map_physmem(a, s, MAP_NOCACHE); - *size = (u32)s; + *ptrp = map_physmem(a, s, MAP_NOCACHE); + *sizep = (u32)s; return 0; }