[dpdk-dev] virtio: fix crash if CQ is not negotiated

Message ID 1432549252-8630-1-git-send-email-damarion@cisco.com (mailing list archive)
State Accepted, archived
Headers

Commit Message

Damjan Marion (damarion) May 25, 2015, 10:20 a.m. UTC
  Fix NULL dereference if virtio control queue is not negotiated.

Signed-off-by: Damjan Marion <damarion@cisco.com>
---
 drivers/net/virtio/virtio_ethdev.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)
  

Comments

Stephen Hemminger May 26, 2015, 2:59 p.m. UTC | #1
On Mon, 25 May 2015 12:20:52 +0200
Damjan Marion <damarion@cisco.com> wrote:

> Fix NULL dereference if virtio control queue is not negotiated.
> 
> Signed-off-by: Damjan Marion <damarion@cisco.com>

This is good belt and suspenders thing to have, but did you see early
patches to check the feature bits and not call this code?

Acked-by: Stephen Hemminger <stephen@networkplumber.org>
  
Thomas Monjalon June 12, 2015, 12:50 p.m. UTC | #2
> > Fix NULL dereference if virtio control queue is not negotiated.
> > 
> > Signed-off-by: Damjan Marion <damarion@cisco.com>
> 
> This is good belt and suspenders thing to have, but did you see early
> patches to check the feature bits and not call this code?
> 
> Acked-by: Stephen Hemminger <stephen@networkplumber.org>

Applied, thanks
  

Patch

diff --git a/drivers/net/virtio/virtio_ethdev.c b/drivers/net/virtio/virtio_ethdev.c
index f74e413..3633fce 100644
--- a/drivers/net/virtio/virtio_ethdev.c
+++ b/drivers/net/virtio/virtio_ethdev.c
@@ -114,19 +114,20 @@  static int
 virtio_send_command(struct virtqueue *vq, struct virtio_pmd_ctrl *ctrl,
 		int *dlen, int pkt_num)
 {
-	uint16_t head = vq->vq_desc_head_idx, i;
+	uint32_t head, i;
 	int k, sum = 0;
 	virtio_net_ctrl_ack status = ~0;
 	struct virtio_pmd_ctrl result;
 
 	ctrl->status = status;
 
-	if (!vq->hw->cvq) {
+	if (!(vq && vq->hw->cvq)) {
 		PMD_INIT_LOG(ERR,
 			     "%s(): Control queue is not supported.",
 			     __func__);
 		return -1;
 	}
+	head = vq->vq_desc_head_idx;
 
 	PMD_INIT_LOG(DEBUG, "vq->vq_desc_head_idx = %d, status = %d, "
 		"vq->hw->cvq = %p vq = %p",