[tpm2] Re: Tss2_Tcti_Device_Init context not zeroed

Antonio de Moraes, Marcos <marcos.antonio-de-moraes at hpe.com> Wed, 13 Jul 2022 21:50:52 +0000
Newsgroups dev.linux.lists.tpm2
Message-ID <PH0PR84MB152820EA35FFF0B7CCEC20E09D899@PH0PR84MB1528.NAMPRD84.PROD.OUTLOOK.COM>
Thanks Willian!

I found that the issue that I reported is already fixed on commit [fda07f78d93a85b7146501b70d8e655d92783fb4] tcti-device: 'partial' may be used uninitialized
<
commit fda07f78d93a85b7146501b70d8e655d92783fb4 (HEAD)
Author: Jeffrey Ferreira jeffpferreira(a)gmail.com<mailto:jeffpferreira(a)gmail.com>
Date:   Tue Mar 30 12:15:01 2021 -0700

    tcti-device: 'partial' may be used uninitialized

    If partial read is not supported then tcti_common->partial will be used
    uninitialized in tcti_device_receive().

    Signed-off-by: Jeffrey Ferreira jeffpferreira(a)gmail.com<mailto:jeffpferreira(a)gmail.com>

diff --git a/src/tss2-tcti/tcti-device.c b/src/tss2-tcti/tcti-device.c
index c606bad1..21a1652f 100644
--- a/src/tss2-tcti/tcti-device.c
+++ b/src/tss2-tcti/tcti-device.c
@@ -412,6 +412,7 @@ Tss2_Tcti_Device_Init (
     tcti_common->state = TCTI_STATE_TRANSMIT;
     memset (&tcti_common->header, 0, sizeof (tcti_common->header));
     tcti_common->locality = 3;
+    tcti_common->partial = false;
     if (conf == NULL) {
         LOG_TRACE ("No TCTI device file specified");
>

Taking the release 3.20 - it has this commit- I built and installed it on my system and now I no longer need to provide a zeroed context memory block to Tss2_Tcti_Device_Init.

Thank you,
Marcos Moraes


From: Roberts, William C <william.c.roberts(a)intel.com>
Sent: terça-feira, 12 de julho de 2022 10:53
To: Antonio de Moraes, Marcos <marcos.antonio-de-moraes(a)hpe.com>; tpm2(a)lists.01.org
Subject: Re: Tss2_Tcti_Device_Init context not zeroed

+ list

> 1 - Is mandatory zeroing it before calling  Tss2_Tcti_Device_Init? If so,  is it a case of missing specification?

No it shouldn't be required IIUC

> 2 - No, it isn't, so is there a bug?

Looks like a bug and it looks consistent throughout all the init routines for TCTIs.
________________________________
From: Antonio de Moraes, Marcos <marcos.antonio-de-moraes(a)hpe.com<mailto:marcos.antonio-de-moraes(a)hpe.com>>
Sent: Monday, July 11, 2022 1:21 PM
To: tpm2-owner(a)lists.01.org<mailto:tpm2-owner(a)lists.01.org> <tpm2-owner(a)lists.01.org<mailto:tpm2-owner(a)lists.01.org>>
Subject: Tss2_Tcti_Device_Init context not zeroed


Hi all,



  I noticed when performing subsequent tpm2 calls over a not zeroed tcti context  passed to Tss2_Tcti_Device_Init I have errors such as:



"WARNING:tcti:src/tss2-tcti/tcti-device.c:321:tcti_device_receive() TPM2 response size disagrees with number of bytes read from fd 3. Header says 0 but we read 29 bytes.

ERROR:sys:src/tss2-sys/api/Tss2_Sys_Execute.c:118:Tss2_Sys_ExecuteFinish() Malformed response: Invalid tag in response header: 0"



I made some experiments:  If I put some content different than 0x00 at offset 89 in memory block passed to RC Tss2_Tcti_Device_Init it fails. That is also true for some other offsets.







TSS2_RC Tss2_Tcti_Device_Init (TSS2_TCTI_CONTEXT *tctiContext, size_t *size, const char *conf);



I check the description of Tss2_Tcti_Device_Init and didn't find any observation that tctiContext parameter must point an zeroed memory block, although in the usage examples the allocated memory is zeroed , calling calloc( 1, <needed size>).



Regarding tctiContext memory block passed to Tss2_Tcti_Device_Init:

1 - Is mandatory zeroing it before calling  Tss2_Tcti_Device_Init? If so,  is it a case of missing specification?

2 - No, it isn't, so is there a bug?



My environment:

TCTI shared library: libtss2-tcti-device.so.0

OS: Enterprise Suse Linux





Thanks in advance,



Marcos A. de Moraes

HPE Security Software Engineer
attachment.htm (text/html, 11.5 KB)
<html xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<!--[if !mso]><style>v\:* {behavior:url(#default#VML);}
o\:* {behavior:url(#default#VML);}
w\:* {behavior:url(#default#VML);}
.shape {behavior:url(#default#VML);}
</style><![endif]--><style><!--
/* Font Definitions */
@font-face
	{font-family:"Cambria Math";
	panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
	{font-family:Calibri;
	panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
	{margin:0cm;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
	{mso-style-priority:99;
	color:#0563C1;
	text-decoration:underline;}
p.xmsonormal, li.xmsonormal, div.xmsonormal
	{mso-style-name:x_msonormal;
	margin:0cm;
	font-size:11.0pt;
	font-family:"Calibri",sans-serif;}
span.EmailStyle20
	{mso-style-type:personal-reply;
	font-family:"Calibri",sans-serif;
	color:windowtext;}
.MsoChpDefault
	{mso-style-type:export-only;
	font-size:10.0pt;}
@page WordSection1
	{size:612.0pt 792.0pt;
	margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
	{page:WordSection1;}
--></style><!--[if gte mso 9]><xml>
<o:shapedefaults v:ext="edit" spidmax="1026" />
</xml><![endif]--><!--[if gte mso 9]><xml>
<o:shapelayout v:ext="edit">
<o:idmap v:ext="edit" data="1" />
</o:shapelayout></xml><![endif]-->
</head>
<body lang="EN-GB" link="#0563C1" vlink="#954F72" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Thanks Willian!<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">I found that the issue that I reported is already fixed on commit
<b>[fda07f78d93a85b7146501b70d8e655d92783fb4] tcti-device: 'partial' may be used uninitialized<o:p></o:p></b></span></p>
<p class="MsoNormal"><b><span style="mso-fareast-language:EN-US">&lt;</span></b><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">commit fda07f78d93a85b7146501b70d8e655d92783fb4 (HEAD)<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Author: Jeffrey Ferreira
<a href="mailto:[email protected]">[email protected]</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Date:&nbsp;&nbsp; Tue Mar 30 12:15:01 2021 -0700<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; tcti-device: 'partial' may be used uninitialized<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; <o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp;If partial read is not supported then tcti_common-&gt;partial will be used<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; uninitialized in tcti_device_receive().<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp; <o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp;Signed-off-by: Jeffrey Ferreira
<a href="mailto:[email protected]">[email protected]</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">diff --git a/src/tss2-tcti/tcti-device.c b/src/tss2-tcti/tcti-device.c<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">index c606bad1..21a1652f 100644<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">--- a/src/tss2-tcti/tcti-device.c<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">+++ b/src/tss2-tcti/tcti-device.c<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">@@ -412,6 +412,7 @@ Tss2_Tcti_Device_Init (<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp; tcti_common-&gt;state = TCTI_STATE_TRANSMIT;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp; memset (&amp;tcti_common-&gt;header, 0, sizeof (tcti_common-&gt;header));<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp; tcti_common-&gt;locality = 3;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">+&nbsp;&nbsp;&nbsp; tcti_common-&gt;partial = false;<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (conf == NULL) {<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; LOG_TRACE (&quot;No TCTI device file specified&quot;);<o:p></o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">&gt;<o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US">Taking the release 3.20 - it has this commit- I built and installed it on my system and now I no longer need to provide a zeroed context memory block to
</span>Tss2_Tcti_Device_Init.<o:p></o:p></p>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<p class="MsoNormal">Thank you,<o:p></o:p></p>
<p class="MsoNormal">Marcos Moraes<o:p></o:p></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<p class="MsoNormal"><span style="mso-fareast-language:EN-US"><o:p>&nbsp;</o:p></span></p>
<div>
<div style="border:none;border-top:solid #E1E1E1 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal"><b><span lang="EN-US">From:</span></b><span lang="EN-US"> Roberts, William C &lt;[email protected]&gt;
<br>
<b>Sent:</b> terça-feira, 12 de julho de 2022 10:53<br>
<b>To:</b> Antonio de Moraes, Marcos &lt;[email protected]&gt;; [email protected]<br>
<b>Subject:</b> Re: Tss2_Tcti_Device_Init context not zeroed<o:p></o:p></span></p>
</div>
</div>
<p class="MsoNormal"><o:p>&nbsp;</o:p></p>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">+ list<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p>&nbsp;</o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">&gt; 1 &#8211; Is mandatory zeroing it before calling &nbsp;Tss2_Tcti_Device_Init? If so, &nbsp;is it a case of missing specification?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p>&nbsp;</o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">No it shouldn't be required IIUC<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p>&nbsp;</o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">&gt; 2 &#8211; No, it isn&#8217;t, so is there a bug?<o:p></o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black"><o:p>&nbsp;</o:p></span></p>
</div>
<div>
<p class="MsoNormal"><span style="font-size:12.0pt;color:black">Looks like a bug and it looks consistent throughout all the init routines for TCTIs.<o:p></o:p></span></p>
</div>
<div class="MsoNormal" align="center" style="text-align:center">
<hr size="2" width="98%" align="center">
</div>
<div id="divRplyFwdMsg">
<p class="MsoNormal"><b><span style="color:black">From:</span></b><span style="color:black"> Antonio de Moraes, Marcos &lt;</span><a href="mailto:[email protected]">[email protected]</a><span style="color:black">&gt;<br>
<b>Sent:</b> Monday, July 11, 2022 1:21 PM<br>
<b>To:</b> </span><a href="mailto:[email protected]">[email protected]</a><span style="color:black"> &lt;</span><a href="mailto:[email protected]">[email protected]</a><span style="color:black">&gt;<br>
<b>Subject:</b> Tss2_Tcti_Device_Init context not zeroed</span> <o:p></o:p></p>
<div>
<p class="MsoNormal">&nbsp;<o:p></o:p></p>
</div>
</div>
<div>
<div>
<p class="xmsonormal">Hi all,<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">&nbsp; I noticed when performing subsequent tpm2 calls over a not zeroed tcti context &nbsp;passed to Tss2_Tcti_Device_Init I have errors such as:<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">&#8220;WARNING:tcti:src/tss2-tcti/tcti-device.c:321:tcti_device_receive() TPM2 response size disagrees with number of bytes read from fd 3<b>. Header says 0 but we read 29 bytes</b>.
<o:p></o:p></p>
<p class="xmsonormal">ERROR:sys:src/tss2-sys/api/Tss2_Sys_Execute.c:118:Tss2_Sys_ExecuteFinish() Malformed response: Invalid tag in response header: 0&#8221;<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">I made some experiments: &nbsp;If I put some content different than 0x00 at offset 89 in memory block passed to RC Tss2_Tcti_Device_Init it fails. That is also true for some other offsets.<o:p></o:p></p>
<p class="xmsonormal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; <o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">TSS2_RC Tss2_Tcti_Device_Init (TSS2_TCTI_CONTEXT *tctiContext, size_t *size, const char *conf);<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">I check the description of Tss2_Tcti_Device_Init and didn&#8217;t find any observation that tctiContext parameter must point an zeroed memory block, although in the usage examples the allocated memory is zeroed , calling calloc( 1, &lt;needed size&gt;).<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">Regarding tctiContext memory block passed to Tss2_Tcti_Device_Init:<o:p></o:p></p>
<p class="xmsonormal" style="text-indent:36.0pt">1 &#8211; Is mandatory zeroing it before calling &nbsp;Tss2_Tcti_Device_Init? If so, &nbsp;is it a case of missing specification?<o:p></o:p></p>
<p class="xmsonormal" style="text-indent:36.0pt">2 &#8211; No, it isn&#8217;t, so is there a bug?<o:p></o:p></p>
<p class="xmsonormal" style="text-indent:36.0pt">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">My environment:<o:p></o:p></p>
<p class="xmsonormal" style="text-indent:36.0pt">TCTI shared library: libtss2-tcti-device.so.0<o:p></o:p></p>
<p class="xmsonormal" style="text-indent:36.0pt">OS: Enterprise Suse Linux<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">Thanks in advance,<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">Marcos A. de Moraes<o:p></o:p></p>
<p class="xmsonormal">HPE Security Software Engineer<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
<p class="xmsonormal">&nbsp;<o:p></o:p></p>
</div>
</div>
</div>
</body>
</html>