Skip to contentSkip to conversation

vhost: Fix Segmentation fault of NULL address

PATCH In review Michael Qiu 3 participants 5 messages Mar 26, 2015 – Mar 27, 2015 1 message not in the archive

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 vhost: Fix Segmentation fault of NULL address

Function gpa_to_vva() could return zero, while this will lead a Segmentation fault.

This patch is to fix this issue.

---
 lib/librte_vhost/vhost_rxtx.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_vhost/vhost_rxtx.c +3 -0
index 535c7a1..23c8acb 100644
@@ -587,6 +587,9 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 		/* Buffer address translation. */
 		vb_addr = gpa_to_vva(dev, desc->addr);
+		if (!vb_addr)
+			return entry_success;
+
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);
 
Signature · 1 line
1.9.3
#1 lore raw
Quoted 15 lines · Michael

Function gpa_to_vva() could return zero, while this will lead a Segmentation fault.

This patch is to fix this issue.

---
 lib/librte_vhost/vhost_rxtx.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_vhost/vhost_rxtx.c +0 -0
index 535c7a1..23c8acb 100644

lib/librte_vhost/vhost_rxtx.c rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, · line 592

Quoted 6 lines
lib/librte_vhost/vhost_rxtx.c +3 -0
@@ -587,6 +587,9 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 		/* Buffer address translation. */
 		vb_addr = gpa_to_vva(dev, desc->addr);
+		if (!vb_addr)
+			return entry_success;
+

Firstly we should add check for all gpa_to_vva translation, and do reporting and cleanup on error. We should avoid the case that some buggy or malicious guest virtio driver gives us an invalid GPA(for example, GPA for some MMIO space) and crash our vhost process.

As we discuss, you meet segfault here, but our virtio PMD shouldn't give us the GPA that has no translation, so we should root cause first and fix the problem, and then submit the patch checking all gpa_to_vva translation.

-Huawei

Quoted 3 lines
lib/librte_vhost/vhost_rxtx.c +0 -0
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);
 
#2 lore raw
Quoted 17 lines · Huawei
Quoted 16 lines · Michael

Function gpa_to_vva() could return zero, while this will lead a Segmentation fault.

This patch is to fix this issue.

---
 lib/librte_vhost/vhost_rxtx.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_vhost/vhost_rxtx.c +0 -0
index 535c7a1..23c8acb 100644
@@ -587,6 +587,9 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
Quoted 9 lines

lib/librte_vhost/vhost_rxtx.c rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, · line 592

Quoted 5 lines
lib/librte_vhost/vhost_rxtx.c +3 -0
 		/* Buffer address translation. */
 		vb_addr = gpa_to_vva(dev, desc->addr);
+		if (!vb_addr)
+			return entry_success;
+

Firstly we should add check for all gpa_to_vva translation, and do reporting and cleanup on error. We should avoid the case that some buggy or malicious guest virtio driver gives us an invalid GPA(for example, GPA for some MMIO space) and crash our vhost process.

Yes, agree, I will do this for next version.

Quoted 2 lines

As we discuss, you meet segfault here, but our virtio PMD shouldn't give us the GPA that has no translation, so we should root cause first and

Yes, root cause is very important, but it will spend lots time, and I think we could be possible to apply this first(All check version).

Thanks,
Michael

Quoted 8 lines

fix the problem, and then submit the patch checking all gpa_to_vva translation.

-Huawei

Quoted 3 lines
lib/librte_vhost/vhost_rxtx.c +0 -0
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);
 
#4 lore raw
In reply to a message not in the archive
Quoted 28 lines · Michael
Quoted 17 lines · Huawei
Quoted 16 lines · Michael

Function gpa_to_vva() could return zero, while this will lead a Segmentation fault.

This patch is to fix this issue.

---
 lib/librte_vhost/vhost_rxtx.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_vhost/vhost_rxtx.c +0 -0
index 535c7a1..23c8acb 100644
@@ -587,6 +587,9 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
Quoted 9 lines

lib/librte_vhost/vhost_rxtx.c rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, · line 592

Quoted 5 lines
lib/librte_vhost/vhost_rxtx.c +3 -0
 		/* Buffer address translation. */
 		vb_addr = gpa_to_vva(dev, desc->addr);
+		if (!vb_addr)
+			return entry_success;
+

Firstly we should add check for all gpa_to_vva translation, and do reporting and cleanup on error. We should avoid the case that some buggy or malicious guest virtio driver gives us an invalid GPA(for example, GPA for some MMIO space) and crash our vhost process.

Quoted 8 lines

Yes, agree, I will do this for next version.

Quoted 2 lines

As we discuss, you meet segfault here, but our virtio PMD shouldn't give us the GPA that has no translation, so we should root cause first and

Yes, root cause is very important, but it will spend lots time, and I think we could be possible to apply this first(All check version).

How to deal with invalid address but not NULL?

Quoted 13 lines

Thanks,
Michael

Quoted 8 lines

fix the problem, and then submit the patch checking all gpa_to_vva translation.

-Huawei

Quoted 3 lines
lib/librte_vhost/vhost_rxtx.c +0 -0
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);
 
#5 lore raw
Quoted 29 lines · Linhaifeng
Quoted 27 lines · Michael
Quoted 26 lines · Huawei
Quoted 15 lines · Michael

Function gpa_to_vva() could return zero, while this will lead a Segmentation fault.

This patch is to fix this issue.

---
 lib/librte_vhost/vhost_rxtx.c | 3 +++
 1 file changed, 3 insertions(+)
lib/librte_vhost/vhost_rxtx.c +0 -0
index 535c7a1..23c8acb 100644

lib/librte_vhost/vhost_rxtx.c rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id, · line 592

Quoted 6 lines
lib/librte_vhost/vhost_rxtx.c +3 -0
@@ -587,6 +587,9 @@ rte_vhost_dequeue_burst(struct virtio_net *dev, uint16_t queue_id,
 
 		/* Buffer address translation. */
 		vb_addr = gpa_to_vva(dev, desc->addr);
+		if (!vb_addr)
+			return entry_success;
+

Firstly we should add check for all gpa_to_vva translation, and do reporting and cleanup on error. We should avoid the case that some buggy or malicious guest virtio driver gives us an invalid GPA(for example, GPA for some MMIO space) and crash our vhost process.

Quoted 8 lines
Quoted 7 lines

Yes, agree, I will do this for next version.

Quoted 2 lines

As we discuss, you meet segfault here, but our virtio PMD shouldn't give us the GPA that has no translation, so we should root cause first and

Yes, root cause is very important, but it will spend lots time, and I think we could be possible to apply this first(All check version).

How to deal with invalid address but not NULL?

The problem is how do you know if it is a valid addres?

Thanks,
Michael

Quoted 13 lines
Quoted 12 lines

Thanks,
Michael

Quoted 7 lines

fix the problem, and then submit the patch checking all gpa_to_vva translation.

-Huawei

Quoted 3 lines
lib/librte_vhost/vhost_rxtx.c +0 -0
 		/* Prefetch buffer address. */
 		rte_prefetch0((void *)(uintptr_t)vb_addr);