qemu-devel
[Top][All Lists]
Advanced

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

Re: [Qemu-devel] [PATCH v1] tpm: check localities index


From: Stefan Berger
Subject: Re: [Qemu-devel] [PATCH v1] tpm: check localities index
Date: Tue, 20 Nov 2018 10:52:41 -0500
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.0

On 11/20/18 2:22 AM, P J P wrote:
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
after setting new 'locty' via 'tpm_tis_new_active_locality'.
Add check to avoid OOB access.

Do you have test code that can set the memory to such a locality or is this purely hypothetical at the moment?

We are registering this MMIO area:

    memory_region_init_io(&s->mmio, OBJECT(s), &tpm_tis_memory_ops,
                          s, "tpm-tis-mmio",
                          TPM_TIS_NUM_LOCALITIES << TPM_TIS_LOCALITY_SHIFT);

#define TPM_TIS_NUM_LOCALITIES      5

#define TPM_TIS_LOCALITY_SHIFT      12

--> 5 << 12 = 0x5000, thus we get memory locations [0 .. 0x4fff]


We have the following code to get from an address to the locality:

static uint8_t tpm_tis_locality_from_addr(hwaddr addr)
{
    return (uint8_t)((addr >> TPM_TIS_LOCALITY_SHIFT) & 0x7);
}

With this we would get localities of [0x0 .. 0x4] following the memory locations [0 .. 0x4fff] above.


    Stefan



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

Update: add assert() calls
   -> https://lists.gnu.org/archive/html/qemu-devel/2018-11/msg00912.html

diff --git a/hw/tpm/tpm_tis.c b/hw/tpm/tpm_tis.c
index 12f5c9a759..d6bf3ceb26 100644
--- a/hw/tpm/tpm_tis.c
+++ b/hw/tpm/tpm_tis.c
@@ -293,6 +293,7 @@ static void tpm_tis_request_completed(TPMIf *ti, int ret)
      uint8_t locty = s->cmd.locty;
      uint8_t l;

+    assert(TPM_TIS_IS_VALID_LOCTY(locty));
      if (s->cmd.selftest_done) {
          for (l = 0; l < TPM_TIS_NUM_LOCALITIES; l++) {
              s->loc[locty].sts |= TPM_TIS_STS_SELFTEST_DONE;
@@ -401,6 +402,7 @@ static uint64_t tpm_tis_mmio_read(void *opaque, hwaddr addr,
      uint32_t avail;
      uint8_t v;

+    assert(TPM_TIS_IS_VALID_LOCTY(locty));
      if (tpm_backend_had_startup_error(s->be_driver)) {
          return 0;
      }
@@ -523,6 +525,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
      uint16_t len;
      uint32_t mask = (size == 1) ? 0xff : ((size == 2) ? 0xffff : ~0);

+    assert(TPM_TIS_IS_VALID_LOCTY(locty));
      trace_tpm_tis_mmio_write(size, addr, val);

      if (locty == 4) {
@@ -642,7 +645,7 @@ static void tpm_tis_mmio_write(void *opaque, hwaddr addr,
              }
          }

-        if (set_new_locty) {
+        if (set_new_locty && TPM_TIS_IS_VALID_LOCTY(active_locty)) {
              tpm_tis_new_active_locality(s, active_locty);
          }





reply via email to

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