Skip to content

Commit

Permalink
vfio: Fix overrun after readlink() fills buffer completely
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
Markus Armbruster authored and awilliam committed Feb 26, 2014
1 parent d5001cf commit 13665a2
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions hw/misc/vfio.c
Expand Up @@ -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;
Expand Down

0 comments on commit 13665a2

Please sign in to comment.