From: Duncan.Palmer at data61.csiro.au
To: tpm2@lists.01.org
Subject: Re: [tpm2] NVRAM_write, BUFFER_SIZE is 0
Date: Tue, 17 Apr 2018 22:24:44 +0000 [thread overview]
Message-ID: <1524003884018.79616@data61.csiro.au> (raw)
In-Reply-To: CAAxBZJtK+WTgBtJkK2BuC9i_Tzby0n3nN-Of8h+EdVd0V1D3cw@mail.gmail.com
[-- Attachment #1: Type: text/plain, Size: 3045 bytes --]
We see the same behaviour on an Intel NUC5i7. I haven't looked at the capabilities reported by the TPM device on that platform. The attached patch (setting max_data_size = MAX_NV_BUFFER_SIZE when max_data_size is reported as 0), sorts the problem out.
Dunk
Duncan Palmer
Senior Software Engineer | Autonomous Systems
Data61 | CSIRO
E duncan.palmer(a)csiro.au
Queensland Centre for Advanced Technologies (QCAT),
1 Technology Court, Pullenvale QLD, 4069
www.data61.csiro.au<http://my.csiro.au/Business-Units/Operations/Communication/CSIRO-Branding/Data61-Branding/www.data61.csiro.au>
CSIRO's Digital Productivity business unit and NICTA have joined forces to create digital powerhouse Data61
________________________________
From: tpm2 <tpm2-bounces(a)lists.01.org> on behalf of Ian Oliver <ian.justin.oliver(a)gmail.com>
Sent: 17 April 2018 21:10
To: tpm2(a)lists.01.org
Subject: [tpm2] NVRAM_write, BUFFER_SIZE is 0
Hi,
we're having problems writing to NV_RAM with tpm2_nvwrite. We can define areas but not write
$ tpm2_nvlist
0x1800005:
hash algorithm:
friendly: sha256
value: 0xB
attributes:
friendly: ownerwrite|policywrite|ownerread|written
value: 0xA000220
size: 32
$ echo -n "hello" | tpm2_nvwrite -x 0x1800005 -a 0x40000001 -V
INFO on line: "135" in file: "tools/tpm2_nvwrite.c": The data(size=0) to be written:
INFO on line: "149" in file: "tools/tpm2_nvwrite.c": Success to write NV area at index 0x1800005 (25165829) offset 0x0.
INFO on line: "135" in file: "tools/tpm2_nvwrite.c": The data(size=0) to be written:
INFO on line: "149" in file: "tools/tpm2_nvwrite.c": Success to write NV area at index 0x1800005 (25165829) offset 0x0.
INFO on line: "135" in file: "tools/tpm2_nvwrite.c": The data(size=0) to be written:
INFO on line: "149" in file: "tools/tpm2_nvwrite.c": Success to write NV area at index 0x1800005 (25165829) offset 0x0.
INFO on line: "135" in file: "tools/tpm2_nvwrite.c": The data(size=0) to be written:
INFO on line: "149" in file: "tools/tpm2_nvwrite.c": Success to write NV area at index 0x1800005 (25165829) offset 0x0.
INFO on line: "135" in file: "tools/tpm2_nvwrite.c": The data(size=0) to be written:
INFO on line: "149" in file: "tools/tpm2_nvwrite.c": Success to write NV area at index 0x1800005 (25165829) offset 0x0.
...
Which loops infinitely
Relevant parts of the tpm2-tools and tpm2-tss code:
file: tpm2_nvwrite.c
113 res = tpm2_util_nv_max_buffer_size(sapi_context, &max_data_size);
The call to tpm2_nv_read_public should get the TPM_PT_NV_BUFFER_MAX capability but and store it to max_data_size.
In that part of the code max_data_size gets set to 0 and that causes the loop above.
The TPM_PT_NV_BUFFER_MAX seems not to be defined in the capabilities for this device: Infineon TPM 2.0 9665 as reported by tpm2_cap.
t.
Ian
--
Dr. Ian Oliver
===============================
Privacy Engineering: via Amazon<http://www.amazon.co.uk/dp/1497569710>
Twitter: @i_j_oliver
[-- Attachment #2: attachment.html --]
[-- Type: text/html, Size: 9270 bytes --]
[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #3: max_data_size.patch --]
[-- Type: text/x-patch, Size: 1337 bytes --]
commit c60f3528a1d4d147f45cb73b3698f1395b67a647
Author: Duncan Palmer <duncan.palmer@csiro.au>
Date: Fri Feb 9 10:01:36 2018 +1000
tpm2_nv(read|write): use a default buffer size if TPM reports 0.
On a NUC5i7RYH, the TPM reports it's max NV buffer size as 0, which
means we can neither read nor write. In this case, default to
MAX_NV_BUFFER_SIZE.
diff --git a/tools/tpm2_nvread.c b/tools/tpm2_nvread.c
index 9d71fd4..251eb5b 100644
--- a/tools/tpm2_nvread.c
+++ b/tools/tpm2_nvread.c
@@ -123,6 +123,9 @@ static bool nv_read(TSS2_SYS_CONTEXT *sapi_context, tpm2_option_flags flags) {
if (max_data_size > MAX_NV_BUFFER_SIZE) {
max_data_size = MAX_NV_BUFFER_SIZE;
}
+ if (max_data_size == 0) {
+ max_data_size = MAX_NV_BUFFER_SIZE;
+ }
UINT8 *data_buffer = malloc(data_size);
if (!data_buffer) {
diff --git a/tools/tpm2_nvwrite.c b/tools/tpm2_nvwrite.c
index 278e733..14c0b0d 100644
--- a/tools/tpm2_nvwrite.c
+++ b/tools/tpm2_nvwrite.c
@@ -119,6 +119,9 @@ static bool nv_write(TSS2_SYS_CONTEXT *sapi_context) {
if (max_data_size > MAX_NV_BUFFER_SIZE) {
max_data_size = MAX_NV_BUFFER_SIZE;
}
+ if (max_data_size == 0) {
+ max_data_size = MAX_NV_BUFFER_SIZE;
+ }
UINT16 data_offset = 0;
UINT16 bytes_left = ctx.nv_buffer.t.size;
next reply other threads:[~2018-04-17 22:24 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-04-17 22:24 Duncan.Palmer [this message]
-- strict thread matches above, loose matches on Subject: below --
2018-04-30 18:12 [tpm2] NVRAM_write, BUFFER_SIZE is 0 Roberts, William C
2018-04-26 22:15 Duncan.Palmer
2018-04-25 17:02 Ian Oliver
2018-04-25 16:29 Roberts, William C
2018-04-24 14:47 Ian Oliver
2018-04-24 12:51 Duncan.Palmer
2018-04-18 18:17 Tadeusz Struk
2018-04-18 8:07 Ian Oliver
2018-04-17 11:10 Ian Oliver
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1524003884018.79616@data61.csiro.au \
--to=tpm2@lists.01.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox