Skip to contentSkip to conversation

vmbus: coverity bug fixes

PATCH Applied Stephen Hemminger 2 participants 5 messages Aug 6, 2018 – Aug 7, 2018

lore
Share & tools
lore
#0 lore raw

cover vmbus: coverity bug fixes

Recent Covertity scan reported some issues in code that is unlikely to be used, but fix it anyway.

Stephen Hemminger (3):
vmbus: close directory in error path
vmbus: make sure path is null terminated
vmbus: handle eof on irq read

 drivers/bus/vmbus/linux/vmbus_uio.c | 20 ++++++++++++++------
 1 file changed, 14 insertions(+), 6 deletions(-)
Signature · 1 line
2.18.0
#1 lore raw

PATCH 1/3 vmbus: close directory in error path

Fix bug reported by Coverity where directory being scanned was not closed in error path (leaking file descriptor).

Coverity issue: 302848

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/linux/vmbus_uio.c | 1 +
 1 file changed, 1 insertion(+)
drivers/bus/vmbus/linux/vmbus_uio.c +1 -0
index b0f8ebaea6ea..0b1b153cc017 100644
@@ -357,6 +357,7 @@ int vmbus_uio_get_subchan(struct vmbus_channel *primary,
 		if (err) {
 			VMBUS_LOG(NOTICE, "invalid subchannel id %lu",
 				  subid);
+			closedir(chan_dir);
 			return err;
 		}
 
Signature · 1 line
2.18.0
#2 lore raw

PATCH 2/3 vmbus: make sure path is null terminated

In reply to Stephen Hemminger

Use strlcpy rather than strncpy to avoid any issues about null termination.

Coverity issue 302859

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/linux/vmbus_uio.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/bus/vmbus/linux/vmbus_uio.c +2 -1
index 0b1b153cc017..bc2c6235e6bc 100644
@@ -18,6 +18,7 @@
 #include <rte_common.h>
 #include <rte_malloc.h>
 #include <rte_bus_vmbus.h>
+#include <rte_string_fns.h>
 
 #include "private.h"
 
@@ -89,7 +90,7 @@ vmbus_uio_alloc_resource(struct rte_vmbus_device *dev,
 		goto error;
 	}
 
-	strncpy((*uio_res)->path, devname, PATH_MAX);
+	strlcpy((*uio_res)->path, devname, PATH_MAX);
 	rte_uuid_copy((*uio_res)->id, dev->device_id);
 
 	return 0;
Signature · 1 line
2.18.0
#3 lore raw

PATCH 3/3 vmbus: handle eof on irq read

In reply to Stephen Hemminger

This function is not used by netvsc driver yet. Still the code should handle case where device driver returns zero (due to rescind).

Coverity issue: 302871

Fixes 831dba47bd36 ("bus/vmbus: add Hyper-V virtual bus support")
---
 drivers/bus/vmbus/linux/vmbus_uio.c | 16 +++++++++++-----
 1 file changed, 11 insertions(+), 5 deletions(-)
drivers/bus/vmbus/linux/vmbus_uio.c +11 -5
index bc2c6235e6bc..856c6d66785d 100644
@@ -39,11 +39,17 @@ void vmbus_uio_irq_control(struct rte_vmbus_device *dev, int32_t onoff)
 int vmbus_uio_irq_read(struct rte_vmbus_device *dev)
 {
 	int32_t count;
-
-	if (read(dev->intr_handle.fd, &count, sizeof(count)) < 0) {
-		VMBUS_LOG(ERR, "cannot read to %d:%s",
-			dev->intr_handle.fd, strerror(errno));
-		count = -errno;
+	int cc;
+
+	cc = read(dev->intr_handle.fd, &count, sizeof(count));
+	if (cc < (int)sizeof(count)) {
+		if (cc < 0) {
+			VMBUS_LOG(ERR, "IRQ read failed %s",
+				  strerror(errno));
+			return -errno;
+		}
+		VMBUS_LOG(ERR, "can't read IRQ count");
+		return -EINVAL;
 	}
 
 	return count;
Signature · 1 line
2.18.0
#4 lore raw
In reply to Stephen Hemminger

06/08/2018 20:11, Stephen Hemminger:

Quoted 7 lines

Recent Covertity scan reported some issues in code that is unlikely to be used, but fix it anyway.

Stephen Hemminger (3):
vmbus: close directory in error path
vmbus: make sure path is null terminated
vmbus: handle eof on irq read

Applied, thanks