[6/7] vhost: validate index in async API

Message ID 20201019173415.582407-7-maxime.coquelin@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: Maxime Coquelin
Headers
Series vhost: make VQ metadata dereferencing robust |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

Maxime Coquelin Oct. 19, 2020, 5:34 p.m. UTC
  This patch validates the queue index parameter, in order
to ensure no out-of-bound accesses happen.

Fixes: 9eed6bfd2efb ("vhost: allow to enable or disable features")
Cc: stable@dpdk.org

Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
 lib/librte_vhost/vhost.c | 6 ++++++
 1 file changed, 6 insertions(+)
  

Comments

Chenbo Xia Oct. 21, 2020, 11:31 a.m. UTC | #1
> -----Original Message-----
> From: Maxime Coquelin <maxime.coquelin@redhat.com>
> Sent: Tuesday, October 20, 2020 1:34 AM
> To: dev@dpdk.org; Xia, Chenbo <chenbo.xia@intel.com>; amorenoz@redhat.com
> Cc: Maxime Coquelin <maxime.coquelin@redhat.com>; stable@dpdk.org
> Subject: [PATCH 6/7] vhost: validate index in async API
> 
> This patch validates the queue index parameter, in order
> to ensure no out-of-bound accesses happen.
> 
> Fixes: 9eed6bfd2efb ("vhost: allow to enable or disable features")
> Cc: stable@dpdk.org
> 
> Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
> ---
>  lib/librte_vhost/vhost.c | 6 ++++++
>  1 file changed, 6 insertions(+)
> 
> diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
> index f78bdfcc94..e92ff618ac 100644
> --- a/lib/librte_vhost/vhost.c
> +++ b/lib/librte_vhost/vhost.c
> @@ -1577,6 +1577,9 @@ int rte_vhost_async_channel_register(int vid,
> uint16_t queue_id,
> 
>  	f.intval = features;
> 
> +	if (queue_id >= VHOST_MAX_VRING)
> +		return -1;
> +
>  	vq = dev->virtqueue[queue_id];
> 
>  	if (unlikely(vq == NULL || !dev->async_copy))
> @@ -1658,6 +1661,9 @@ int rte_vhost_async_channel_unregister(int vid,
> uint16_t queue_id)
>  	if (dev == NULL)
>  		return ret;
> 
> +	if (queue_id >= VHOST_MAX_VRING)
> +		return ret;
> +
>  	vq = dev->virtqueue[queue_id];
> 
>  	if (vq == NULL)
> --
> 2.26.2

Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
  

Patch

diff --git a/lib/librte_vhost/vhost.c b/lib/librte_vhost/vhost.c
index f78bdfcc94..e92ff618ac 100644
--- a/lib/librte_vhost/vhost.c
+++ b/lib/librte_vhost/vhost.c
@@ -1577,6 +1577,9 @@  int rte_vhost_async_channel_register(int vid, uint16_t queue_id,
 
 	f.intval = features;
 
+	if (queue_id >= VHOST_MAX_VRING)
+		return -1;
+
 	vq = dev->virtqueue[queue_id];
 
 	if (unlikely(vq == NULL || !dev->async_copy))
@@ -1658,6 +1661,9 @@  int rte_vhost_async_channel_unregister(int vid, uint16_t queue_id)
 	if (dev == NULL)
 		return ret;
 
+	if (queue_id >= VHOST_MAX_VRING)
+		return ret;
+
 	vq = dev->virtqueue[queue_id];
 
 	if (vq == NULL)