From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: dev@dpdk.org, david.marchand@redhat.com, chenbo.xia@intel.com,
mb@smartsharesystems.com
Cc: Maxime Coquelin <maxime.coquelin@redhat.com>, stable@dpdk.org
Subject: [PATCH 2/7] vhost: fix missing check on virtqueue access
Date: Mon, 25 Sep 2023 18:36:05 +0200 [thread overview]
Message-ID: <20230925163610.3307750-3-maxime.coquelin@redhat.com> (raw)
In-Reply-To: <20230925163610.3307750-1-maxime.coquelin@redhat.com>
Acquiring the access lock is not enough to ensure
virtqueue's metadata such as vring pointers are valid.
The access status must also be checked.
Fixes: 4e0de8dac853 ("vhost: protect vring access done by application")
Cc: stable@dpdk.org
Signed-off-by: Maxime Coquelin <maxime.coquelin@redhat.com>
---
lib/vhost/vhost.c | 16 ++++++++++++++--
1 file changed, 14 insertions(+), 2 deletions(-)
diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
index e9c775fa26..83b71ffb23 100644
--- a/lib/vhost/vhost.c
+++ b/lib/vhost/vhost.c
@@ -1416,7 +1416,10 @@ rte_vhost_avail_entries(int vid, uint16_t queue_id)
rte_rwlock_write_lock(&vq->access_lock);
- if (unlikely(!vq->enabled || vq->avail == NULL))
+ if (unlikely(!vq->access_ok))
+ goto out;
+
+ if (unlikely(!vq->enabled))
goto out;
ret = *(volatile uint16_t *)&vq->avail->idx - vq->last_used_idx;
@@ -1508,9 +1511,15 @@ rte_vhost_enable_guest_notification(int vid, uint16_t queue_id, int enable)
rte_rwlock_write_lock(&vq->access_lock);
+ if (unlikely(!vq->access_ok)) {
+ ret = -1;
+ goto out_unlock;
+ }
+
vq->notif_enable = enable;
ret = vhost_enable_guest_notification(dev, vq, enable);
+out_unlock:
rte_rwlock_write_unlock(&vq->access_lock);
return ret;
@@ -1601,7 +1610,10 @@ rte_vhost_rx_queue_count(int vid, uint16_t qid)
rte_rwlock_write_lock(&vq->access_lock);
- if (unlikely(!vq->enabled || vq->avail == NULL))
+ if (unlikely(!vq->access_ok))
+ goto out;
+
+ if (unlikely(!vq->enabled))
goto out;
ret = *((volatile uint16_t *)&vq->avail->idx) - vq->last_avail_idx;
--
2.41.0
next prev parent reply other threads:[~2023-09-25 16:36 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20230925163610.3307750-1-maxime.coquelin@redhat.com>
2023-09-25 16:36 ` [PATCH 1/7] vhost: fix missing vring call " Maxime Coquelin
2023-10-19 7:24 ` David Marchand
2023-10-20 8:40 ` Maxime Coquelin
2023-09-25 16:36 ` Maxime Coquelin [this message]
2023-09-25 16:36 ` [PATCH 3/7] vhost: fix checking virtqueue access when notifying guest Maxime Coquelin
2023-09-25 16:36 ` [PATCH 4/7] vhost: fix check on virtqueue access in async registration Maxime Coquelin
2023-09-25 16:36 ` [PATCH 5/7] vhost: Fix check on virtqueue access in in-flight getter Maxime Coquelin
2023-09-25 16:36 ` [PATCH 6/7] vhost: fix missing lock protection in power monitor API Maxime Coquelin
2023-09-25 16:36 ` [PATCH 7/7] vhost: fix checking virtqueue access ins stats API Maxime Coquelin
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=20230925163610.3307750-3-maxime.coquelin@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=chenbo.xia@intel.com \
--cc=david.marchand@redhat.com \
--cc=dev@dpdk.org \
--cc=mb@smartsharesystems.com \
--cc=stable@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).