From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: Li Feng <fengli@smartx.com>, Chenbo Xia <chenbo.xia@intel.com>
Cc: dev@dpdk.org
Subject: Re: [PATCH v3] vhost: avoid potential null pointer access
Date: Mon, 25 Sep 2023 10:26:23 +0200 [thread overview]
Message-ID: <f374400c-3e98-8d9a-37f3-efd2c96cac2d@redhat.com> (raw)
In-Reply-To: <7136f05c-023b-fda5-44ee-8a26b0c8e548@redhat.com>
On 9/25/23 10:15, Maxime Coquelin wrote:
>
>
> On 9/12/23 09:42, Li Feng wrote:
>> If the user calls rte_vhost_vring_call() on a ring that has been
>> invalidated, we will encounter SEGV.
>>
>> We should check the pointer firstly before accessing it.
>>
>> Signed-off-by: Li Feng <fengli@smartx.com>
>> ---
>> v2 -> v3:
>> - Also fix the rte_vhost_vring_call_nonblock.
>>
>> v1 -> v2:
>> - Fix rebase error.
>>
>>
>>
>> lib/vhost/vhost.c | 14 ++++++++------
>> lib/vhost/vhost.h | 12 ++++++++++--
>> 2 files changed, 18 insertions(+), 8 deletions(-)
>
>
> Thanks for posting the fix, the segmentation fault may indeed happen
> when injecting IRQ from the app directly using the Vhost API. It cannot
> happen when vhost_vring_call() is calle directly from
> rte_enqueue_burst/rte_dequeue_burst though.
>
> so I think below patch would be better:
>
> diff --git a/lib/vhost/vhost.c b/lib/vhost/vhost.c
> index eb6309b681..733e0ab289 100644
> --- a/lib/vhost/vhost.c
> +++ b/lib/vhost/vhost.c
> @@ -1341,6 +1341,9 @@ rte_vhost_vring_call(int vid, uint16_t vring_idx)
>
> rte_rwlock_read_lock(&vq->access_lock);
>
> + if (unlikely(!vq->access_ok))
> + return -1;
> +
> if (vq_is_packed(dev))
> vhost_vring_call_packed(dev, vq);
> else
> @@ -1371,6 +1374,9 @@ rte_vhost_vring_call_nonblock(int vid, uint16_t
> vring_idx)
> if (rte_rwlock_read_trylock(&vq->access_lock))
> return -EAGAIN;
>
> + if (unlikely(!vq->access_ok))
> + return -1;
> +
> if (vq_is_packed(dev))
> vhost_vring_call_packed(dev, vq);
> else
>
>
> Do you confirm that fixes your issue?
As pointed out by David off-list, there are other places where we need
to add this check. I will prepare a patch fixing them all.
Thanks,
Maxime
> Thanks,
> Maxime
next prev parent reply other threads:[~2023-09-25 8:26 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-12 7:42 Li Feng
2023-09-25 8:15 ` Maxime Coquelin
2023-09-25 8:26 ` Maxime Coquelin [this message]
2023-09-25 10:37 ` Morten Brørup
2023-09-25 10:59 ` 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=f374400c-3e98-8d9a-37f3-efd2c96cac2d@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=chenbo.xia@intel.com \
--cc=dev@dpdk.org \
--cc=fengli@smartx.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).