Skip to contentSkip to conversation

tpm: check localities index

PATCH In review P J P 3 participants 6 messages Nov 6, 2018

lore
Share & tools
lore

P J P

author
#0 lore raw

PATCH 1/2 tpm: check localities index

From: Prasad J Pandit <[email protected]>

While performing mmio device r/w operations, guest could set 'addr' parameter such that 'locty' index exceeds TPM_TIS_NUM_LOCALITIES=5. Add check to avoid OOB access.

---
 hw/tpm/tpm_tis.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/tpm/tpm_tis.c +8 -2
index 12f5c9a759..20126dd838 100644
@@ -293,6 +293,10 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
     uint8_t locty = s->cmd.locty;
     uint8_t l;
 
+    if (locty >= TPM_TIS_NUM_LOCALITIES) {
+        return;
+    }
+
     if (s->cmd.selftest_done) {
         for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
             s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
@@ -401,7 +405,8 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
     uint32_t avail;
     uint8_t v;
 
-    if (tpm_backend_had_startup_error(s->be_driver)) {
+    if (tpm_backend_had_startup_error(s->be_driver)
+        || locty >= TPM_TIS_NUM_LOCALITIES) {
         return 0;
     }
 
@@ -530,7 +535,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
         return;
     }
 
-    if (tpm_backend_had_startup_error(s->be_driver)) {
+    if (tpm_backend_had_startup_error(s->be_driver)
+        || locty >= TPM_TIS_NUM_LOCALITIES) {
         return;
     }
 
Signature · 1 line
2.17.2
author
#1 lore raw

PATCH 2/2 tpm: use loop iterator to set sts data field

From: Prasad J Pandit <[email protected]>

When TIS request is done, set 'sts' data field across all localities.

---
 hw/tpm/tpm_tis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +1 -1
index 20126dd838..58d90645bc 100644
@@ -299,7 +299,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
 
     if (s->cmd.selftest_done) {
         for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
-            s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
+            s->loc[l].sts |= TPM_TIS_STS_SELFTEST_DONE;
         }
     }
 
Signature · 1 line
2.17.2
#2 lore raw

Re: [Qemu-devel] [PATCH 2/2] tpm: use loop iterator to set sts data field

Hi

Quoted 4 lines · P J P

From: Prasad J Pandit <[email protected]>

When TIS request is done, set 'sts' data field across all localities.

The code certainly meant to set the field across all localities. However I don't see in the "TCG PC Client Specific TPM Interface Specification (TIS)" where it states that the field should be set across all localities. Could you quote the relevant part?

thanks

Quoted 22 lines
---
 hw/tpm/tpm_tis.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +1 -2
index 20126dd838..58d90645bc 100644
@@ -299,7 +299,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
 
     if (s->cmd.selftest_done) {
         for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
-            s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
+            s->loc[l].sts |= TPM_TIS_STS_SELFTEST_DONE;
         }
     }
 
--

2.17.2

Signature · 1 line
Marc-André Lureau
#5 lore raw
In reply to P J P

Hi

Quoted 7 lines · P J P

From: Prasad J Pandit <[email protected]>

While performing mmio device r/w operations, guest could set 'addr' parameter such that 'locty' index exceeds TPM_TIS_NUM_LOCALITIES=5. Add check to avoid OOB access.

Unless memory_region_init_io() is broken, and the region size is > TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT, I don't see how that could happen. Do you have a reproducer?

Perhaps replace the conditions with an assert instead?

Quoted 45 lines
---
 hw/tpm/tpm_tis.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)
hw/tpm/tpm_tis.c +8 -3
index 12f5c9a759..20126dd838 100644
@@ -293,6 +293,10 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
     uint8_t locty = s->cmd.locty;
     uint8_t l;
 
+    if (locty >= TPM_TIS_NUM_LOCALITIES) {
+        return;
+    }
+
     if (s->cmd.selftest_done) {
         for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
             s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
@@ -401,7 +405,8 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
     uint32_t avail;
     uint8_t v;
 
-    if (tpm_backend_had_startup_error(s->be_driver)) {
+    if (tpm_backend_had_startup_error(s->be_driver)
+        || locty >= TPM_TIS_NUM_LOCALITIES) {
         return 0;
     }
 
@@ -530,7 +535,8 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
         return;
     }
 
-    if (tpm_backend_had_startup_error(s->be_driver)) {
+    if (tpm_backend_had_startup_error(s->be_driver)
+        || locty >= TPM_TIS_NUM_LOCALITIES) {
         return;
     }
 
--

2.17.2

Signature · 1 line
Marc-André Lureau
Reviewed-by on v1 2/2
#4 lore raw

Re: [Qemu-devel] [PATCH 2/2] tpm: use loop iterator to set sts data field

In reply to P J P
Quoted 5 lines · P J P

From: Prasad J Pandit <[email protected]>

When TIS request is done, set 'sts' data field across all localities.

Quoted 17 lines
---
  hw/tpm/tpm_tis.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +1 -1
index 20126dd838..58d90645bc 100644
@@ -299,7 +299,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
 
      if (s->cmd.selftest_done) {
          for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
-            s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
+            s->loc[l].sts |= TPM_TIS_STS_SELFTEST_DONE;
          }
      }
 
#3 lore raw

Re: [Qemu-devel] [PATCH 2/2] tpm: use loop iterator to set sts data field

In reply to Marc-André Lureau
Quoted 10 lines · Marc-André Lureau

Hi

Quoted 3 lines · P J P

From: Prasad J Pandit <[email protected]>

When TIS request is done, set 'sts' data field across all localities.

The code certainly meant to set the field across all localities. However I don't see in the "TCG PC Client Specific TPM Interface Specification (TIS)" where it states that the field should be set across all localities. Could you quote the relevant part?

I don't see it explicitly mentioned but would interpret it as being a flag across all localities.

    Stefan

Quoted 26 lines

thanks

Quoted 22 lines
---
  hw/tpm/tpm_tis.c | 2 +-
  1 file changed, 1 insertion(+), 1 deletion(-)
hw/tpm/tpm_tis.c +1 -2
index 20126dd838..58d90645bc 100644
@@ -299,7 +299,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
 
      if (s->cmd.selftest_done) {
          for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
-            s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
+            s->loc[l].sts |= TPM_TIS_STS_SELFTEST_DONE;
          }
      }
 
--

2.17.2