From patchwork Mon Oct 28 13:51:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefan Berger X-Patchwork-Id: 2003286 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=koCFQEoZ; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.ozlabs.org (client-ip=112.213.38.117; helo=lists.ozlabs.org; envelope-from=slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org; receiver=patchwork.ozlabs.org) Received: from lists.ozlabs.org (lists.ozlabs.org [112.213.38.117]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4XcZZ972Ddz1xxY for ; Tue, 29 Oct 2024 00:52:01 +1100 (AEDT) Received: from boromir.ozlabs.org (localhost [IPv6:::1]) by lists.ozlabs.org (Postfix) with ESMTP id 4XcZZ80zxXz2yRC for ; Tue, 29 Oct 2024 00:52:00 +1100 (AEDT) X-Original-To: slof@lists.ozlabs.org Delivered-To: slof@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; arc=none smtp.remote-ip=148.163.158.5 ARC-Seal: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1730123518; cv=none; b=FejGrleBReRq1vTuFDOLZ3SQZyTUO8qbu5pUv+qyQYK+KWSeOWxJh61ahrToFRIGu5JxeU2APdjAJydSTZbNNp5gIlYFVrqQEOLvw6hTprneVin0bGXeNpYIspHh8lb4fKVaPiYJbsz6OAFr51MuX8sO1Rtl6NaSWpzp4JCs45NEmtJVho8J/K6UX8rBfALqBe+K1gIBmAIofCLhmqqpXmKD8aKc259Fk81Yo26bD7qpsLplOmz5EMT4i7O8uOjNOchBPwXtsfTy6Yj4WaL4lcvRk2ae2njS2rr4kUcP7YBnK1IS2fj+a+2k0t0R/MqwDnRXS4aZhDW7Q29nI+3YbA== ARC-Message-Signature: i=1; a=rsa-sha256; d=lists.ozlabs.org; s=201707; t=1730123518; c=relaxed/relaxed; bh=nFV+yzxocfsfbZOEBf+/AVabirXqPsVN5ViTBzYEZE0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IsoQ442b7nEXfQSFs72AFyWsJMC7mdXB1JUjGrcn9UeJxTtfCyItBAWMCV+CqZuytmnYzR9nVzOSYvMMIFWTHuAXdn4IiLy9cE0j5IW5v8ycXyKyIOzaSoSSTvYY+dApDyosmW5a8hIwcdZMODVRyhNVe0mgpmlPPS2wLX7L7bKc8tZSlOEu6GaqWl2PkrW1IcXszl5ChEelYDjf3LdPeoN0rHi2kuPTcjnQPj4VYKmC3RFv9jOyofNSAqvCtZfRUVOARVa/rmkcKnWSIM+WS4c8biz0WoAZtGBq8gU5MpSluUq4VMvxWxbTc0Ml3dM+WwrKO/0s3HtLDWlPyK6eQQ== ARC-Authentication-Results: i=1; lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=koCFQEoZ; dkim-atps=neutral; spf=pass (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=stefanb@linux.ibm.com; receiver=lists.ozlabs.org) smtp.mailfrom=linux.ibm.com Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=linux.ibm.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=ibm.com header.i=@ibm.com header.a=rsa-sha256 header.s=pp1 header.b=koCFQEoZ; dkim-atps=neutral Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=linux.ibm.com (client-ip=148.163.158.5; helo=mx0b-001b2d01.pphosted.com; envelope-from=stefanb@linux.ibm.com; receiver=lists.ozlabs.org) Received: from mx0b-001b2d01.pphosted.com (mx0b-001b2d01.pphosted.com [148.163.158.5]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 4XcZZ52DV5z2yMP for ; Tue, 29 Oct 2024 00:51:57 +1100 (AEDT) Received: from pps.filterd (m0360072.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 49S51aqH021827; Mon, 28 Oct 2024 13:51:54 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ibm.com; h=cc :content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=pp1; bh=nFV+yzxocfsfbZOEB f+/AVabirXqPsVN5ViTBzYEZE0=; b=koCFQEoZ1+ElDbmjnHsRSlOzO3I9wkhQ8 +Lw1r/i1gup/0p/0iaV80UFH2L5DVNf2oxKTLVmf+qOycSmqVtL7fylsANVqIgl6 FOILXvlyR4+aln70SBsrLolMAvFk4Ilwp3N1O5HwV51936vLrUwMXy99H2p+3hPL 3BZ5NvxCLpX17ZQ38VsfdtNz35jV2+85AT6o2TZhkcjMksQrVwPoDZIoktV5py3n UW9R1JvLzKozkYy2klLT7b2zFmOArtFIerP25dkXZlXQV+o3hRv7q0hdmYS2YuAY aRg0ei82hMbRNJxp2whE8F7esdR1Evw1Fjl1W4Zxt3qKBBXCSCe8Q== Received: from ppma22.wdc07v.mail.ibm.com (5c.69.3da9.ip4.static.sl-reverse.com [169.61.105.92]) by mx0a-001b2d01.pphosted.com (PPS) with ESMTPS id 42j43ead7e-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2024 13:51:54 +0000 (GMT) Received: from pps.filterd (ppma22.wdc07v.mail.ibm.com [127.0.0.1]) by ppma22.wdc07v.mail.ibm.com (8.18.1.2/8.18.1.2) with ESMTP id 49SBp8dj028275; Mon, 28 Oct 2024 13:51:54 GMT Received: from smtprelay04.dal12v.mail.ibm.com ([172.16.1.6]) by ppma22.wdc07v.mail.ibm.com (PPS) with ESMTPS id 42hb4xpk7m-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 28 Oct 2024 13:51:54 +0000 Received: from smtpav05.dal12v.mail.ibm.com (smtpav05.dal12v.mail.ibm.com [10.241.53.104]) by smtprelay04.dal12v.mail.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id 49SDpqXf47186284 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Mon, 28 Oct 2024 13:51:52 GMT Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id BE0A358065; Mon, 28 Oct 2024 13:51:52 +0000 (GMT) Received: from smtpav05.dal12v.mail.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 8168658056; Mon, 28 Oct 2024 13:51:52 +0000 (GMT) Received: from sbct-3.pok.ibm.com (unknown [9.47.158.153]) by smtpav05.dal12v.mail.ibm.com (Postfix) with ESMTP; Mon, 28 Oct 2024 13:51:52 +0000 (GMT) From: Stefan Berger To: slof@lists.ozlabs.org, aik@ozlabs.ru Date: Mon, 28 Oct 2024 09:51:49 -0400 Message-ID: <20241028135149.3135243-3-stefanb@linux.ibm.com> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241028135149.3135243-1-stefanb@linux.ibm.com> References: <20241028135149.3135243-1-stefanb@linux.ibm.com> MIME-Version: 1.0 X-TM-AS-GCONF: 00 X-Proofpoint-GUID: BXDI_zNtK2dYS1X5EqxTZ-MHPcoV1WfN X-Proofpoint-ORIG-GUID: BXDI_zNtK2dYS1X5EqxTZ-MHPcoV1WfN X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1051,Hydra:6.0.680,FMLib:17.12.62.30 definitions=2024-10-15_01,2024-10-11_01,2024-09-30_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 suspectscore=0 bulkscore=0 impostorscore=0 malwarescore=0 clxscore=1015 priorityscore=1501 mlxlogscore=999 lowpriorityscore=0 adultscore=0 phishscore=0 spamscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2409260000 definitions=main-2410280109 X-Spam-Status: No, score=-0.7 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=disabled version=4.0.0 X-Spam-Checker-Version: SpamAssassin 4.0.0 (2022-12-13) on lists.ozlabs.org Subject: [SLOF] [PATCH 2/2] tpm: Implement firmware API call pass-through-to-tpm X-BeenThere: slof@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "Patches for https://github.com/aik/SLOF" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stefan Berger Errors-To: slof-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "SLOF" Implement the firmware API call pass-through-to-tpm that allows a caller to pass a TPM command to the TPM. Since the buffer provided by the user will be used for returning the TPM's response it must be sufficiently large. To be safe, it should be of the size returned by the firmware API call tpm-get-maximum-cmd-size. Signed-off-by: Stefan Berger --- board-qemu/slof/vio-vtpm-cdriver.fs | 11 +++++++++++ lib/libtpm/tcgbios.c | 16 ++++++++++++++++ lib/libtpm/tcgbios.h | 1 + lib/libtpm/tpm.code | 11 +++++++++++ lib/libtpm/tpm.in | 1 + 5 files changed, 40 insertions(+) diff --git a/board-qemu/slof/vio-vtpm-cdriver.fs b/board-qemu/slof/vio-vtpm-cdriver.fs index 21c2190..59ae5d2 100644 --- a/board-qemu/slof/vio-vtpm-cdriver.fs +++ b/board-qemu/slof/vio-vtpm-cdriver.fs @@ -57,6 +57,17 @@ LOG-SIZE BUFFER: log-base THEN ; +\ firmware API call +: pass-through-to-tpm ( buf-addr buf-size -- rsp-size ) + vtpm-debug? IF + ." Call to pass-through-to-tpm" cr + THEN + tpm-pass-through-to-tpm ( rsp-size ) + vtpm-debug? IF + ." VTPM: tpm-pass-through-to-tpm returned size: " dup . cr + THEN +; + \ firmware API call : get-maximum-cmd-size ( -- max-size ) vtpm-debug? IF diff --git a/lib/libtpm/tcgbios.c b/lib/libtpm/tcgbios.c index a64afde..9fc00fa 100644 --- a/lib/libtpm/tcgbios.c +++ b/lib/libtpm/tcgbios.c @@ -972,6 +972,22 @@ uint32_t tpm_get_maximum_cmd_size(void) return PAPR_VTPM_MAX_BUFFER_SIZE; } +uint32_t tpm_pass_through_to_tpm(void *buffer, uint32_t bufferlen) +{ + unsigned char respbuffer[PAPR_VTPM_MAX_BUFFER_SIZE]; + uint32_t respbufferlen = sizeof(respbuffer); + int ret; + + ret = spapr_transmit(0, buffer, respbuffer, &respbufferlen, + TPM_DURATION_TYPE_LONG); + if (ret) + return 0; + + memcpy(buffer, respbuffer, respbufferlen); + + return respbufferlen; +} + /* * Add an EV_ACTION measurement to the list of measurements */ diff --git a/lib/libtpm/tcgbios.h b/lib/libtpm/tcgbios.h index 83148e0..74344f3 100644 --- a/lib/libtpm/tcgbios.h +++ b/lib/libtpm/tcgbios.h @@ -42,5 +42,6 @@ uint32_t tpm_2hash_ext_log(uint32_t pcrindex, const char *info, uint32_t infolen, const void *data, uint64_t datalen); uint32_t tpm_get_maximum_cmd_size(void); +uint32_t tpm_pass_through_to_tpm(void *buffer, uint32_t bufferlen); #endif /* TCGBIOS_H */ diff --git a/lib/libtpm/tpm.code b/lib/libtpm/tpm.code index 23075b8..5ed3d35 100644 --- a/lib/libtpm/tpm.code +++ b/lib/libtpm/tpm.code @@ -216,3 +216,14 @@ PRIM(tpm_X2d_get_X2d_maximum_X2d_cmd_X2d_size) PUSH; TOS.u = tpm_get_maximum_cmd_size(); MIRP + +/****************************************************************************************/ +/* SLOF: tpm-pass-through-to-tpm ( buf-addr buf-size -- rsp-size ) */ +/* LIBTPM: rsp_size = tpm-pass-through-to-tpm */ +/****************************************************************************************/ +PRIM(tpm_X2d_pass_X2d_through_X2d_to_X2d_tpm) + uint32_t buf_size = TOS.u; POP; + void *buf = TOS.a; + + TOS.u = tpm_pass_through_to_tpm(buf, buf_size); +MIRP diff --git a/lib/libtpm/tpm.in b/lib/libtpm/tpm.in index d76c479..b413a24 100644 --- a/lib/libtpm/tpm.in +++ b/lib/libtpm/tpm.in @@ -31,3 +31,4 @@ cod(tpm-measure-gpt) cod(tpm-hash-log-extend-event-buffer) cod(tpm-2hash-ext-log) cod(tpm-get-maximum-cmd-size) +cod(tpm-pass-through-to-tpm)