qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Qemu-devel] [PATCH 1/2] tpm: check localities index


From: P J P
Subject: [Qemu-devel] [PATCH 1/2] tpm: check localities index
Date: Tue, 6 Nov 2018 10:51:43 +0530

From: Prasad J Pandit <address@hidden>

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.

Reported-by: Cheng Feng <address@hidden>
Signed-off-by: Prasad J Pandit <address@hidden>
---
 hw/tpm/tpm_tis.c | 10 ++++++++--
 1 file changed, 8 insertions(+), 2 deletions(-)

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 12f5c9a759..20126dd838 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -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




reply via email to

[Prev in Thread] Current Thread [Next in Thread]