[v2] vhost: fix possible null pointer dereferencing

Message ID 20181127095451.18217-1-maxime.coquelin@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series [v2] vhost: fix possible null pointer dereferencing |

Checks

Context Check Description
ci/Intel-compilation success Compilation OK
ci/mellanox-Performance-Testing success Performance Testing PASS
ci/intel-Performance-Testing success Performance Testing PASS

Commit Message

Maxime Coquelin Nov. 27, 2018, 9:54 a.m. UTC
  If mmap() call fails in vhost_user_set_mem_table, dev->mem
is set to NULL. If later, qva_to_vva() is called, a segfault
occurs.

Fixes: 8f972312b8f4 ("vhost: support vhost-user")
Cc: stable@dpdk.org

Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/vhost_user.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Jens Freimann Nov. 27, 2018, 10:30 a.m. UTC | #1
On Tue, Nov 27, 2018 at 10:54:51AM +0100, Maxime Coquelin wrote:
>If mmap() call fails in vhost_user_set_mem_table, dev->mem
>is set to NULL. If later, qva_to_vva() is called, a segfault
>occurs.
>
>Fixes: 8f972312b8f4 ("vhost: support vhost-user")
>Cc: stable@dpdk.org
>
>Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
>Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>---
> lib/librte_vhost/vhost_user.c | 6 ++++++
> 1 file changed, 6 insertions(+)
>

Jumping to an out label would have worked as well, but it doesn't
really matter.

Reviewed-by: Jens Freimann <jfreimann@redhat.com>
  
Maxime Coquelin Dec. 11, 2018, 6:30 p.m. UTC | #2
On 11/27/18 11:30 AM, Jens Freimann wrote:
> On Tue, Nov 27, 2018 at 10:54:51AM +0100, Maxime Coquelin wrote:
>> If mmap() call fails in vhost_user_set_mem_table, dev->mem
>> is set to NULL. If later, qva_to_vva() is called, a segfault
>> occurs.
>>
>> Fixes: 8f972312b8f4 ("vhost: support vhost-user")
>> Cc: stable@dpdk.org
>>
>> Reviewed-by: Tiwei Bie <tiwei.bie@intel.com>
>> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
>> ---
>> lib/librte_vhost/vhost_user.c | 6 ++++++
>> 1 file changed, 6 insertions(+)
>>
> 
> Jumping to an out label would have worked as well, but it doesn't
> really matter.
> 
> Reviewed-by: Jens Freimann <jfreimann@redhat.com>
> 


Thanks, applied with label change you suggested.

Maxime
  

Patch

diff --git a/lib/librte_vhost/vhost_user.c b/lib/librte_vhost/vhost_user.c
index 3ea64eba6..9fdd16172 100644
--- a/lib/librte_vhost/vhost_user.c
+++ b/lib/librte_vhost/vhost_user.c
@@ -489,6 +489,12 @@  qva_to_vva(struct virtio_net *dev, uint64_t qva, uint64_t *len)
 	struct rte_vhost_mem_region *r;
 	uint32_t i;
 
+	if (unlikely(!dev || !dev->mem)) {
+		*len = 0;
+
+		return 0;
+	}
+
 	/* Find the region where the address lives. */
 	for (i = 0; i < dev->mem->nregions; i++) {
 		r = &dev->mem->regions[i];