[1/2] vhost: fix queue number check when setting inflight FD

Message ID 20220310125059.30562-1-david.marchand@redhat.com (mailing list archive)
State Accepted, archived
Delegated to: David Marchand
Headers
Series [1/2] vhost: fix queue number check when setting inflight FD |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

David Marchand March 10, 2022, 12:50 p.m. UTC
  From: Chenbo Xia <chenbo.xia@intel.com>

In function vhost_user_set_inflight_fd, queue number in inflight
message is used to access virtqueue. However, queue number could
be larger than VHOST_MAX_VRING and cause write OOB as this number
will be used to write inflight info in virtqueue structure. This
patch checks the queue number to avoid the issue and also make
sure virtqueues are allocated before setting inflight information.

Fixes: ad0a4ae491fe ("vhost: checkout resubmit inflight information")
Cc: stable@dpdk.org

Reported-by: Wenxiang Qian <leonwxqian@gmail.com>
Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
---
 lib/vhost/vhost_user.c | 3 +++
 1 file changed, 3 insertions(+)
  

Comments

Maxime Coquelin March 10, 2022, 1 p.m. UTC | #1
On 3/10/22 13:50, David Marchand wrote:
> From: Chenbo Xia <chenbo.xia@intel.com>
> 
> In function vhost_user_set_inflight_fd, queue number in inflight
> message is used to access virtqueue. However, queue number could
> be larger than VHOST_MAX_VRING and cause write OOB as this number
> will be used to write inflight info in virtqueue structure. This
> patch checks the queue number to avoid the issue and also make
> sure virtqueues are allocated before setting inflight information.
> 
> Fixes: ad0a4ae491fe ("vhost: checkout resubmit inflight information")
> Cc: stable@dpdk.org
> 
> Reported-by: Wenxiang Qian <leonwxqian@gmail.com>
> Signed-off-by: Chenbo Xia <chenbo.xia@intel.com>
> ---
>   lib/vhost/vhost_user.c | 3 +++
>   1 file changed, 3 insertions(+)
> 
> diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
> index 589b950458..1ec4357bee 100644
> --- a/lib/vhost/vhost_user.c
> +++ b/lib/vhost/vhost_user.c
> @@ -2883,6 +2883,9 @@ vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
>   	case VHOST_USER_SET_VRING_ADDR:
>   		vring_idx = ctx->msg.payload.addr.index;
>   		break;
> +	case VHOST_USER_SET_INFLIGHT_FD:
> +		vring_idx = ctx->msg.payload.inflight.num_queues - 1;
> +		break;
>   	default:
>   		return 0;
>   	}

Reviewed-by: Maxime Coquelin <maxime.coquelin@redhat.com>

Thanks,
Maxime
  

Patch

diff --git a/lib/vhost/vhost_user.c b/lib/vhost/vhost_user.c
index 589b950458..1ec4357bee 100644
--- a/lib/vhost/vhost_user.c
+++ b/lib/vhost/vhost_user.c
@@ -2883,6 +2883,9 @@  vhost_user_check_and_alloc_queue_pair(struct virtio_net *dev,
 	case VHOST_USER_SET_VRING_ADDR:
 		vring_idx = ctx->msg.payload.addr.index;
 		break;
+	case VHOST_USER_SET_INFLIGHT_FD:
+		vring_idx = ctx->msg.payload.inflight.num_queues - 1;
+		break;
 	default:
 		return 0;
 	}