patches for DPDK stable branches
 help / color / mirror / Atom feed
From: Kevin Traynor <ktraynor@redhat.com>
To: Wenwu Ma <wenwux.ma@intel.com>, stable@dpdk.org
Cc: chenbo.xia@intel.com, weix.ling@intel.com, yuanx.wang@intel.com,
	xingguang.he@intel.com, yux.jiang@intel.com
Subject: Re: [PATCH 21.11] examples/vhost: fix use after free
Date: Wed, 23 Nov 2022 18:13:46 +0000	[thread overview]
Message-ID: <9c1f0556-89b6-9cb4-9d3d-05cfa9da6f9c@redhat.com> (raw)
In-Reply-To: <20221116014022.1884914-1-wenwux.ma@intel.com>

On 16/11/2022 01:40, Wenwu Ma wrote:
> [ upstream commit 40abb903fe0aff0556d15d96385a4c7b647649b5 ]
> 
> 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")
> 
> Signed-off-by: Wenwu Ma <wenwux.ma@intel.com>
> Tested-by: Wei Ling <weix.ling@intel.com>
> Reviewed-by: Chenbo Xia <chenbo.xia@intel.com>
> ---

Thanks for the backport. This is not pushed to 21.11 branch.

>   examples/vhost/main.c | 21 ++++++++++++---------
>   1 file changed, 12 insertions(+), 9 deletions(-)
> 
> diff --git a/examples/vhost/main.c b/examples/vhost/main.c
> index f9e932061f..36464922e3 100644
> --- a/examples/vhost/main.c
> +++ b/examples/vhost/main.c
> @@ -908,17 +908,10 @@ enqueue_pkts(struct vhost_dev *vdev, struct rte_mbuf **pkts, uint16_t rx_count)
>   	if (builtin_net_driver) {
>   		enqueue_count = vs_enqueue_pkts(vdev, VIRTIO_RXQ, pkts, rx_count);
>   	} else if (async_vhost_driver) {
> -		uint16_t enqueue_fail = 0;
> -
>   		complete_async_pkts(vdev);
>   		enqueue_count = rte_vhost_submit_enqueue_burst(vdev->vid,
>   					VIRTIO_RXQ, pkts, rx_count);
>   		__atomic_add_fetch(&vdev->pkts_inflight, enqueue_count, __ATOMIC_SEQ_CST);
> -
> -		enqueue_fail = rx_count - enqueue_count;
> -		if (enqueue_fail)
> -			free_pkts(&pkts[enqueue_count], enqueue_fail);
> -
>   	} else {
>   		enqueue_count = rte_vhost_enqueue_burst(vdev->vid, VIRTIO_RXQ,
>   						pkts, rx_count);
> @@ -944,8 +937,13 @@ drain_vhost(struct vhost_dev *vdev)
>   				__ATOMIC_SEQ_CST);
>   	}
>   
> -	if (!async_vhost_driver)
> +	if (!async_vhost_driver) {
>   		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
> @@ -1249,8 +1247,13 @@ drain_eth_rx(struct vhost_dev *vdev)
>   				__ATOMIC_SEQ_CST);
>   	}
>   
> -	if (!async_vhost_driver)
> +	if (!async_vhost_driver) {
>   		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);
> +	}
>   }
>   
>   static __rte_always_inline void


      reply	other threads:[~2022-11-23 18:13 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-11-16  1:40 Wenwu Ma
2022-11-23 18:13 ` Kevin Traynor [this message]

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=9c1f0556-89b6-9cb4-9d3d-05cfa9da6f9c@redhat.com \
    --to=ktraynor@redhat.com \
    --cc=chenbo.xia@intel.com \
    --cc=stable@dpdk.org \
    --cc=weix.ling@intel.com \
    --cc=wenwux.ma@intel.com \
    --cc=xingguang.he@intel.com \
    --cc=yuanx.wang@intel.com \
    --cc=yux.jiang@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).