[SLOF] [PATCH 2/2] tpm: Implement firmware API call pass-through-to-tpm

Stefan Berger stefanb at linux.ibm.com
Thu Oct 24 23:10:13 AEDT 2024



On 10/24/24 4:33 AM, Alexey Kardashevskiy wrote:
> 
> 
> On Wed, 23 Oct 2024, at 11:13, Stefan Berger wrote:
> 
> A couple of line about who is going to call tpm-pass-through-to-tpm at all, and why?

It is for support of grub 'Automatic Disk Unlock with TPM2': 
https://lore.kernel.org/grub-devel/qurvz3ceq5fwbbq6c3u6xpmbsjbxnvoqg2tyqq47rdfaemwbl2@mgqwgv5ik445/T/#t

Patches using this code here are in the last patch in this branch:
https://github.com/stefanberger/grub2/commits/tpm2-unlock-v20%2Bppc64/

> 
> 
>> Signed-off-by: Stefan Berger <stefanb at linux.ibm.com>
>> ---
>> board-qemu/slof/vio-vtpm-cdriver.fs | 11 +++++++++++
>> lib/libtpm/tcgbios.c                | 16 ++++++++++++++++
>> lib/libtpm/tcgbios.h                |  1 +
>> lib/libtpm/tpm.code                 | 12 ++++++++++++
>> lib/libtpm/tpm.in                   |  1 +
>> 5 files changed, 41 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)
> 
> 
> bufferlen is not used.
> 
>> +{
>> + 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);
> 
> s/respbufferlen/min(respbufferlen, bufferlen)/ may be? Thanks,
> 
>> +
>> + 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..4a4418e 100644
>> --- a/lib/libtpm/tpm.code
>> +++ b/lib/libtpm/tpm.code
>> @@ -216,3 +216,15 @@ 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)
>> -- 
>> 2.25.1
>>
>>


More information about the SLOF mailing list