qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Markus Armbruster <armbru@redhat.com>
To: qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, alex.williamson@redhat.com
Subject: [Qemu-devel] [PATCH v2 1/2] vfio: Fix overrun after readlink() fills buffer completely
Date: Mon, 24 Feb 2014 14:51:48 +0100	[thread overview]
Message-ID: <1393249909-11202-2-git-send-email-armbru@redhat.com> (raw)
In-Reply-To: <1393249909-11202-1-git-send-email-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>
---
 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;
-- 
1.8.1.4

  reply	other threads:[~2014-02-24 13:52 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-24 13:51 [Qemu-devel] [PATCH v2 0/2] Two buffer overruns in device assignment Markus Armbruster
2014-02-24 13:51 ` Markus Armbruster [this message]
2014-02-24 13:51 ` [Qemu-devel] [PATCH v2 2/2] pci-assign: Fix potential read beyond buffer on -EBUSY Markus Armbruster
2014-02-24 17:39 ` [Qemu-devel] [PATCH v2 0/2] Two buffer overruns in device assignment Alex Williamson
2014-02-24 17:40   ` Peter Maydell
2014-02-24 17:49     ` Alex Williamson

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=1393249909-11202-2-git-send-email-armbru@redhat.com \
    --to=armbru@redhat.com \
    --cc=alex.williamson@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).