qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: "Gabriel L. Somlo" <somlo@cmu.edu>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, jordan.l.justen@intel.com,
	armbru@redhat.com, kraxel@redhat.com, pbonzini@redhat.com,
	markmb@redhat.com, lersek@redhat.com
Subject: [Qemu-devel] [PATCH v5 4/6] fw_cfg: avoid calculating invalid current entry pointer
Date: Thu,  5 Nov 2015 09:32:50 -0500	[thread overview]
Message-ID: <1446733972-1602-5-git-send-email-somlo@cmu.edu> (raw)
In-Reply-To: <1446733972-1602-1-git-send-email-somlo@cmu.edu>

When calculating a pointer to the currently selected fw_cfg item, the
following is used:

  FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];

When s->cur_entry is FW_CFG_INVALID, we are calculating the address of
a non-existent element in s->entries[arch][...], which is undefined.

This patch ensures the resulting entry pointer is set to NULL whenever
s->cur_entry is FW_CFG_INVALID.

Reported-by: Laszlo Ersek <lersek@redhat.com>
Cc: Marc Marí <markmb@redhat.com>
Signed-off-by: Gabriel Somlo <somlo@cmu.edu>
Reviewed-by: Laszlo Ersek <lersek@redhat.com>
---
 hw/nvram/fw_cfg.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/nvram/fw_cfg.c b/hw/nvram/fw_cfg.c
index c2d3a0a..046fa74 100644
--- a/hw/nvram/fw_cfg.c
+++ b/hw/nvram/fw_cfg.c
@@ -277,7 +277,8 @@ static int fw_cfg_select(FWCfgState *s, uint16_t key)
 static uint8_t fw_cfg_read(FWCfgState *s)
 {
     int arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
-    FWCfgEntry *e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
+    FWCfgEntry *e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
+                    &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
     uint8_t ret;
 
     if (s->cur_entry == FW_CFG_INVALID || !e->data || s->cur_offset >= e->len)
@@ -342,7 +343,8 @@ static void fw_cfg_dma_transfer(FWCfgState *s)
     }
 
     arch = !!(s->cur_entry & FW_CFG_ARCH_LOCAL);
-    e = &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
+    e = (s->cur_entry == FW_CFG_INVALID) ? NULL :
+        &s->entries[arch][s->cur_entry & FW_CFG_ENTRY_MASK];
 
     if (dma.control & FW_CFG_DMA_CTL_READ) {
         read = 1;
-- 
2.4.3

  parent reply	other threads:[~2015-11-05 14:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-05 14:32 [Qemu-devel] [PATCH v5 0/6] fw_cfg: spec update, misc. cleanup, optimize read Gabriel L. Somlo
2015-11-05 14:32 ` [Qemu-devel] [PATCH v5 1/6] fw_cfg: move internal function call docs to header file Gabriel L. Somlo
2015-11-05 14:32 ` [Qemu-devel] [PATCH v5 2/6] fw_cfg: amend callback behavior spec to once per select Gabriel L. Somlo
2015-11-05 14:32 ` [Qemu-devel] [PATCH v5 3/6] fw_cfg: remove offset argument from callback prototype Gabriel L. Somlo
2015-11-05 14:32 ` Gabriel L. Somlo [this message]
2015-11-05 14:32 ` [Qemu-devel] [PATCH v5 5/6] fw_cfg: add generic non-DMA read method Gabriel L. Somlo
2015-11-05 16:18   ` Laszlo Ersek
2015-11-05 14:32 ` [Qemu-devel] [PATCH v5 6/6] fw_cfg: replace ioport data read with generic method Gabriel L. Somlo
2015-11-05 16:11   ` Laszlo Ersek
2015-11-23 14:18 ` [Qemu-devel] [PATCH v5 0/6] fw_cfg: spec update, misc. cleanup, optimize read Gabriel L. Somlo
2015-11-24  7:21   ` Gerd Hoffmann
2015-11-24 12:29     ` Gabriel L. Somlo

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=1446733972-1602-5-git-send-email-somlo@cmu.edu \
    --to=somlo@cmu.edu \
    --cc=armbru@redhat.com \
    --cc=jordan.l.justen@intel.com \
    --cc=kraxel@redhat.com \
    --cc=lersek@redhat.com \
    --cc=markmb@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-devel@nongnu.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;
as well as URLs for NNTP newsgroup(s).