From: Wenwu Ma <wenwux.ma@intel.com>
To: maxime.coquelin@redhat.com, chenbo.xia@intel.com, dev@dpdk.org
Cc: jiayu.hu@intel.com, yinan.wang@intel.com, xingguang.he@intel.com,
weix.ling@intel.com, yuanx.wang@intel.com,
Wenwu Ma <wenwux.ma@intel.com>,
stable@dpdk.org
Subject: [PATCH] examples/vhost: fix use after free
Date: Thu, 14 Jul 2022 13:11:06 +0800 [thread overview]
Message-ID: <20220714051106.1134222-1-wenwux.ma@intel.com> (raw)
In async_enqueue_pkts(), the failed pkts will
be freed before return, but, the failed pkts may be
retried later, it will cause use after free. So,
we free the failed pkts after retry.
Fixes: 1907ce4baec3 ("examples/vhost: fix retry logic on Rx path")
Cc: stable@dpdk.org
Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
---
examples/vhost/main.c | 19 ++++++++++++-------
1 file changed, 12 insertions(+), 7 deletions(-)
diff --git a/examples/vhost/main.c b/examples/vhost/main.c
index 7e1666f42a..7956dc4f13 100644
--- a/examples/vhost/main.c
+++ b/examples/vhost/main.c
@@ -1073,8 +1073,13 @@ drain_vhost(struct vhost_dev *vdev)
__ATOMIC_SEQ_CST);
}
- if (!dma_bind[vid2socketid[vdev->vid]].dmas[VIRTIO_RXQ].async_enabled)
+ if (!dma_bind[vid2socketid[vdev->vid]].dmas[VIRTIO_RXQ].async_enabled) {
free_pkts(m, nr_xmit);
+ } else {
+ uint16_t enqueue_fail = nr_xmit - ret;
+ if (enqueue_fail > 0)
+ free_pkts(&m[ret], enqueue_fail);
+ }
}
static __rte_always_inline void
@@ -1350,17 +1355,12 @@ async_enqueue_pkts(struct vhost_dev *dev, uint16_t queue_id,
struct rte_mbuf **pkts, uint32_t rx_count)
{
uint16_t enqueue_count;
- uint16_t enqueue_fail = 0;
uint16_t dma_id = dma_bind[vid2socketid[dev->vid]].dmas[VIRTIO_RXQ].dev_id;
complete_async_pkts(dev);
enqueue_count = rte_vhost_submit_enqueue_burst(dev->vid, queue_id,
pkts, rx_count, dma_id, 0);
- enqueue_fail = rx_count - enqueue_count;
- if (enqueue_fail)
- free_pkts(&pkts[enqueue_count], enqueue_fail);
-
return enqueue_count;
}
@@ -1405,8 +1405,13 @@ drain_eth_rx(struct vhost_dev *vdev)
__ATOMIC_SEQ_CST);
}
- if (!dma_bind[vid2socketid[vdev->vid]].dmas[VIRTIO_RXQ].async_enabled)
+ if (!dma_bind[vid2socketid[vdev->vid]].dmas[VIRTIO_RXQ].async_enabled) {
free_pkts(pkts, rx_count);
+ } else {
+ uint16_t enqueue_fail = rx_count - enqueue_count;
+ if (enqueue_fail > 0)
+ free_pkts(&pkts[enqueue_count], enqueue_fail);
+ }
}
uint16_t async_dequeue_pkts(struct vhost_dev *dev, uint16_t queue_id,
--
2.25.1
next reply other threads:[~2022-07-14 5:16 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-14 5:11 Wenwu Ma [this message]
2022-07-14 7:55 ` Ling, WeiX
2022-07-15 5:54 ` Xia, Chenbo
2022-09-22 13:46 ` Xia, Chenbo
2022-09-29 8:40 ` Xia, Chenbo
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=20220714051106.1134222-1-wenwux.ma@intel.com \
--to=wenwux.ma@intel.com \
--cc=chenbo.xia@intel.com \
--cc=dev@dpdk.org \
--cc=jiayu.hu@intel.com \
--cc=maxime.coquelin@redhat.com \
--cc=stable@dpdk.org \
--cc=weix.ling@intel.com \
--cc=xingguang.he@intel.com \
--cc=yinan.wang@intel.com \
--cc=yuanx.wang@intel.com \
/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).