Two buffer overruns in device assignment
v2 cover Two buffer overruns in device assignment
v2:
* Treat readlink() filling buffer as error (Alex)
* Use sizeof() rather than PATH_MAX (Peter)
* PATCH 2/2 unchanged
Markus Armbruster (2):
vfio: Fix overrun after readlink() fills buffer completely
pci-assign: Fix potential read beyond buffer on -EBUSY
hw/i386/kvm/pci-assign.c | 1 + hw/misc/vfio.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.1.4
PATCH v2 1/2 vfio: Fix overrun after readlink() fills buffer completely
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.
--- hw/misc/vfio.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
hw/misc/vfio.c +3 -3
@@ -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 ;
Signature · 1 line
1.8.1.4
PATCH v2 2/2 pci-assign: Fix potential read beyond buffer on -EBUSY
In reply to Markus Armbrusterreadlink() doesn't write a terminating null byte. assign_failed_examine() passes the unterminated string to strrchr(). Oops. Terminate it.
Spotted by Coverity.
--- hw/i386/kvm/pci-assign.c | 1 + 1 file changed, 1 insertion(+)
hw/i386/kvm/pci-assign.c +1 -0
@@ -743,6 +743,7 @@ static void assign_failed_examine(AssignedDevice *dev) goto fail; } + driver[r] =0 ; ns =strrchr (driver,'/' );if (!ns) { goto fail;
Signature · 1 line
1.8.1.4
Quoted 5 lines · Markus Armbruster
v2:
* Treatreadlink()filling buffer as error (Alex)
* Usesizeof()rather thanPATH_MAX(Peter)
* PATCH 2/2 unchanged
Quoted 7 lines
Markus Armbruster (2):
vfio: Fix overrun afterreadlink()fills buffer completely
pci-assign: Fix potential read beyond buffer on-EBUSYhw/i386/kvm/pci-assign.c | 1 + hw/misc/vfio.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
For both:
Peter, if you want to grab these directly, feel free, otherwise I can shepherd them in through vfio. Thanks,
Alex
Quoted 14 lines · Alex Williamson
Quoted 5 lines · Markus Armbruster
v2:
* Treatreadlink()filling buffer as error (Alex)
* Usesizeof()rather thanPATH_MAX(Peter)
* PATCH 2/2 unchangedQuoted 7 lines
Markus Armbruster (2):
vfio: Fix overrun afterreadlink()fills buffer completely
pci-assign: Fix potential read beyond buffer on-EBUSYhw/i386/kvm/pci-assign.c | 1 + hw/misc/vfio.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
Quoted 6 lines
For both:
Acked-by Alex Williamson <[email protected]>Peter, if you want to grab these directly, feel free, otherwise I can shepherd them in through vfio. Thanks,
Via vfio would be easiest for me.
thanks
-- PMM
Quoted 15 lines · Peter Maydell
Quoted 14 lines · Alex Williamson
Quoted 12 lines · Markus Armbruster
v2:
* Treatreadlink()filling buffer as error (Alex)
* Usesizeof()rather thanPATH_MAX(Peter)
* PATCH 2/2 unchangedMarkus Armbruster (2):
vfio: Fix overrun afterreadlink()fills buffer completely
pci-assign: Fix potential read beyond buffer on-EBUSYhw/i386/kvm/pci-assign.c | 1 + hw/misc/vfio.c | 6 +++--- 2 files changed, 4 insertions(+), 3 deletions(-)
Quoted 8 lines
Quoted 6 lines
For both:
Acked-by Alex Williamson <[email protected]>Peter, if you want to grab these directly, feel free, otherwise I can shepherd them in through vfio. Thanks,
Via vfio would be easiest for me.
Ok