qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Alex Williamson <alex.williamson@redhat.com>
To: anthony@redhat.com
Cc: Markus Armbruster <armbru@redhat.com>, qemu-devel@nongnu.org
Subject: [Qemu-devel] [PULL 1/4] vfio: Fix overrun after readlink() fills buffer completely
Date: Wed, 26 Feb 2014 11:25:55 -0700	[thread overview]
Message-ID: <20140226182555.8018.44958.stgit@bling.home> (raw)
In-Reply-To: <20140226182246.8018.81349.stgit@bling.home>

From: Markus Armbruster <armbru@redhat.com>

readlink() returns the number of bytes written to the buffer, and it
doesn't write a terminating null byte.  vfio_init() writes it itself.
Overruns the buffer when readlink() filled it completely.

Fix by treating readlink() filling the buffer completely as error,
like we do in pci-assign.c's assign_failed_examine().

Spotted by Coverity.

Signed-off-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Alex Williamson <alex.williamson@redhat.com>
---
 hw/misc/vfio.c |    6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/hw/misc/vfio.c b/hw/misc/vfio.c
index 8db182f..e669bbe 100644
--- a/hw/misc/vfio.c
+++ b/hw/misc/vfio.c
@@ -3681,10 +3681,10 @@ static int vfio_initfn(PCIDevice *pdev)
 
     strncat(path, "iommu_group", sizeof(path) - strlen(path) - 1);
 
-    len = readlink(path, iommu_group_path, PATH_MAX);
-    if (len <= 0) {
+    len = readlink(path, iommu_group_path, sizeof(path));
+    if (len <= 0 || len >= sizeof(path)) {
         error_report("vfio: error no iommu_group for device");
-        return -errno;
+        return len < 0 ? -errno : ENAMETOOLONG;
     }
 
     iommu_group_path[len] = 0;

  reply	other threads:[~2014-02-26 18:26 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-26 18:25 [Qemu-devel] [PULL 0/4] vfio update and fix + pci-assign fix Alex Williamson
2014-02-26 18:25 ` Alex Williamson [this message]
2014-02-26 18:26 ` [Qemu-devel] [PULL 2/4] pci-assign: Fix potential read beyond buffer on -EBUSY Alex Williamson
2014-02-26 18:26 ` [Qemu-devel] [PULL 3/4] qdev-monitor: set DeviceState opts before calling realize Alex Williamson
2014-02-26 18:26 ` [Qemu-devel] [PULL 4/4] vfio: blacklist loading of unstable roms Alex Williamson
2014-02-26 18:29 ` [Qemu-devel] [PULL 0/4] vfio update and fix + pci-assign fix Alex Williamson
2014-02-27 11:51 ` 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=20140226182555.8018.44958.stgit@bling.home \
    --to=alex.williamson@redhat.com \
    --cc=anthony@redhat.com \
    --cc=armbru@redhat.com \
    --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).