qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: P J P <ppandit@redhat.com>
To: Qemu Developers <qemu-devel@nongnu.org>
Cc: Stefan Berger <stefanb@linux.vnet.ibm.com>,
	Prasad J Pandit <pjp@fedoraproject.org>
Subject: [Qemu-devel] [PATCH 1/2] tpm: check localities index
Date: Tue,  6 Nov 2018 10:51:43 +0530	[thread overview]
Message-ID: <20181106052144.31841-1-ppandit@redhat.com> (raw)

From: Prasad J Pandit <pjp@fedoraproject.org>

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 <PSIRT@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 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	other threads:[~2018-11-06  5:23 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-06  5:21 P J P [this message]
2018-11-06  5:21 ` [Qemu-devel] [PATCH 2/2] tpm: use loop iterator to set sts data field P J P
2018-11-06  8:13   ` Marc-André Lureau
2018-11-06 14:28     ` Stefan Berger
2018-11-06 14:26   ` Stefan Berger
2018-11-06  8:07 ` [Qemu-devel] [PATCH 1/2] tpm: check localities index Marc-André Lureau

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=20181106052144.31841-1-ppandit@redhat.com \
    --to=ppandit@redhat.com \
    --cc=pjp@fedoraproject.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanb@linux.vnet.ibm.com \
    /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;
as well as URLs for NNTP newsgroup(s).