All of lore.kernel.org
 help / color / mirror / Atom feed
From: Claudio Fontana <cfontana@suse.de>
To: dev@dpdk.org
Cc: Claudio Fontana <cfontana@suse.de>
Subject: [PATCH 2/2] vhost: improve error handling in desc_to_mbuf
Date: Mon,  1 Aug 2022 13:53:20 +0200	[thread overview]
Message-ID: <20220801115320.17186-3-cfontana@suse.de> (raw)
In-Reply-To: <20220801115320.17186-1-cfontana@suse.de>

check when increasing vec_idx that it is still valid
in the (buf_len < dev->vhost_hlen) case too.

Signed-off-by: Claudio Fontana <cfontana@suse.de>
---
 lib/vhost/virtio_net.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/lib/vhost/virtio_net.c b/lib/vhost/virtio_net.c
index 0b8db2046e..6d34feaf73 100644
--- a/lib/vhost/virtio_net.c
+++ b/lib/vhost/virtio_net.c
@@ -2701,12 +2701,15 @@ desc_to_mbuf(struct virtio_net *dev, struct vhost_virtqueue *vq,
 	if (unlikely(buf_len < dev->vhost_hlen)) {
 		buf_offset = dev->vhost_hlen - buf_len;
 		vec_idx++;
+		if (unlikely(vec_idx >= nr_vec))
+			goto error;
 		buf_addr = buf_vec[vec_idx].buf_addr;
 		buf_iova = buf_vec[vec_idx].buf_iova;
 		buf_len = buf_vec[vec_idx].buf_len;
 		buf_avail  = buf_len - buf_offset;
 	} else if (buf_len == dev->vhost_hlen) {
-		if (unlikely(++vec_idx >= nr_vec))
+		vec_idx++;
+		if (unlikely(vec_idx >= nr_vec))
 			goto error;
 		buf_addr = buf_vec[vec_idx].buf_addr;
 		buf_iova = buf_vec[vec_idx].buf_iova;
-- 
2.26.2


  parent reply	other threads:[~2022-08-01 11:53 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-08-01 11:53 [PATCH 0/2] vhost fixes for OVS SIGSEGV in PMD Claudio Fontana
2022-08-01 11:53 ` [PATCH 1/2] vhost: fix error handling in virtio_dev_tx_split Claudio Fontana
2022-08-01 11:53 ` Claudio Fontana [this message]
  -- strict thread matches above, loose matches on Subject: below --
2022-08-02  0:39 [PATCH v2 0/2] vhost fixes for OVS SIGSEGV in PMD Claudio Fontana
2022-08-02  0:39 ` [PATCH 2/2] vhost: improve error handling in desc_to_mbuf Claudio Fontana
2022-07-31 20:17 [PATCH 0/2] vhost fixes for OVS SIGSEGV in PMD Claudio Fontana
2022-07-31 20:17 ` [PATCH 2/2] vhost: improve error handling in desc_to_mbuf Claudio Fontana

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220801115320.17186-3-cfontana@suse.de \
    --to=cfontana@suse.de \
    --cc=dev@dpdk.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.