From: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
To: qemu-devel@nongnu.org
Cc: marcel.apfelbaum@gmail.com, yuval.shaia@oracle.com,
peter.maydell@linaro.org, f4bug@amsat.org
Subject: [Qemu-devel] [PULL 5/8] hw/rdma: Fix possible out of bounds access to regs array
Date: Thu, 3 May 2018 21:21:22 +0300 [thread overview]
Message-ID: <20180503182125.20310-6-marcel.apfelbaum@gmail.com> (raw)
In-Reply-To: <20180503182125.20310-1-marcel.apfelbaum@gmail.com>
From: Yuval Shaia <yuval.shaia@oracle.com>
Coverity (CID1390589, CID1390608).
Array size is RDMA_BAR1_REGS_SIZE, let's make sure the given address is
in range.
While there also:
1. Adjust the size of this bar to reasonable size
2. Report the size of the array with sizeof(array)
Reported-by: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Yuval Shaia <yuval.shaia@oracle.com>
Reviewed-by: Marcel Apfelbaum <marcel.apfelbaum@gmail.com>
Message-Id: <20180430200223.4119-6-marcel.apfelbaum@gmail.com>
---
hw/rdma/vmw/pvrdma.h | 6 +++---
hw/rdma/vmw/pvrdma_main.c | 4 ++--
2 files changed, 5 insertions(+), 5 deletions(-)
diff --git a/hw/rdma/vmw/pvrdma.h b/hw/rdma/vmw/pvrdma.h
index 8c173cb824..0b46dc5a9b 100644
--- a/hw/rdma/vmw/pvrdma.h
+++ b/hw/rdma/vmw/pvrdma.h
@@ -31,7 +31,7 @@
#define RDMA_REG_BAR_IDX 1
#define RDMA_UAR_BAR_IDX 2
#define RDMA_BAR0_MSIX_SIZE (16 * 1024)
-#define RDMA_BAR1_REGS_SIZE 256
+#define RDMA_BAR1_REGS_SIZE 64
#define RDMA_BAR2_UAR_SIZE (0x1000 * MAX_UCS) /* each uc gets page */
/* MSIX */
@@ -86,7 +86,7 @@ static inline int get_reg_val(PVRDMADev *dev, hwaddr addr, uint32_t *val)
{
int idx = addr >> 2;
- if (idx > RDMA_BAR1_REGS_SIZE) {
+ if (idx >= RDMA_BAR1_REGS_SIZE) {
return -EINVAL;
}
@@ -99,7 +99,7 @@ static inline int set_reg_val(PVRDMADev *dev, hwaddr addr, uint32_t val)
{
int idx = addr >> 2;
- if (idx > RDMA_BAR1_REGS_SIZE) {
+ if (idx >= RDMA_BAR1_REGS_SIZE) {
return -EINVAL;
}
diff --git a/hw/rdma/vmw/pvrdma_main.c b/hw/rdma/vmw/pvrdma_main.c
index 994220b58e..3ed7409763 100644
--- a/hw/rdma/vmw/pvrdma_main.c
+++ b/hw/rdma/vmw/pvrdma_main.c
@@ -449,14 +449,14 @@ static void init_bars(PCIDevice *pdev)
/* BAR 1 - Registers */
memset(&dev->regs_data, 0, sizeof(dev->regs_data));
memory_region_init_io(&dev->regs, OBJECT(dev), ®s_ops, dev,
- "pvrdma-regs", RDMA_BAR1_REGS_SIZE);
+ "pvrdma-regs", sizeof(dev->regs_data));
pci_register_bar(pdev, RDMA_REG_BAR_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY,
&dev->regs);
/* BAR 2 - UAR */
memset(&dev->uar_data, 0, sizeof(dev->uar_data));
memory_region_init_io(&dev->uar, OBJECT(dev), &uar_ops, dev, "rdma-uar",
- RDMA_BAR2_UAR_SIZE);
+ sizeof(dev->uar_data));
pci_register_bar(pdev, RDMA_UAR_BAR_IDX, PCI_BASE_ADDRESS_SPACE_MEMORY,
&dev->uar);
}
--
2.14.3
next prev parent reply other threads:[~2018-05-03 18:20 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-05-03 18:21 [Qemu-devel] [PULL 0/8] RDMA queue Marcel Apfelbaum
2018-05-03 18:21 ` [Qemu-devel] [PULL 1/8] hw/rdma: Fix possible munmap call on a NULL pointer Marcel Apfelbaum
2018-05-03 18:21 ` [Qemu-devel] [PULL 2/8] hw/rdma: Fix possible usage of " Marcel Apfelbaum
2018-05-03 18:21 ` [Qemu-devel] [PULL 3/8] hw/rdma: Delete port's pkey table Marcel Apfelbaum
2018-05-03 18:21 ` [Qemu-devel] [PULL 4/8] hw/rdma: Fix possible out of bounds access to GID table Marcel Apfelbaum
2018-05-03 18:21 ` Marcel Apfelbaum [this message]
2018-05-03 18:21 ` [Qemu-devel] [PULL 6/8] hw/rdma: Delete duplicate definition of MAX_RM_TBL_NAME Marcel Apfelbaum
2018-05-03 18:21 ` [Qemu-devel] [PULL 7/8] hw/rdma: Fix possible out of bounds access to port GID index Marcel Apfelbaum
2018-05-03 18:21 ` [Qemu-devel] [PULL 8/8] MAINTAINERS: update Marcel Apfelbaum email Marcel Apfelbaum
2018-05-04 8:24 ` [Qemu-devel] [PULL 0/8] RDMA queue Peter Maydell
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=20180503182125.20310-6-marcel.apfelbaum@gmail.com \
--to=marcel.apfelbaum@gmail.com \
--cc=f4bug@amsat.org \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=yuval.shaia@oracle.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).