From: Maxime Coquelin <maxime.coquelin@redhat.com>
To: "Morten Brørup" <mb@smartsharesystems.com>,
"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 12:59:28 +0200 [thread overview]
Message-ID: <a0d1717f-bf87-7eab-d0a7-94114c861d5a@redhat.com> (raw)
In-Reply-To: <98CBD80474FA8B44BF855DF32C47DC35D87C05@smartserver.smartshare.dk>
On 9/25/23 12:37, Morten Brørup wrote:
>> From: Maxime Coquelin [mailto:maxime.coquelin@redhat.com]
>> Sent: Monday, 25 September 2023 10.15
>>
>> 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;
>
> Don't you need to release the lock before returning here?
Of course yes, I actually caught it after sending my reply, it is
already fixed locally.
But thanks for the review, much appreciated!
Maxime
>> +
>> 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;
>
> Don't you need to release the lock before returning here?
>
>> +
>> if (vq_is_packed(dev))
>> vhost_vring_call_packed(dev, vq);
>> else
>>
>>
>> Do you confirm that fixes your issue?
>>
>> Thanks,
>> Maxime
>
prev parent reply other threads:[~2023-09-25 10:59 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
2023-09-25 10:37 ` Morten Brørup
2023-09-25 10:59 ` Maxime Coquelin [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=a0d1717f-bf87-7eab-d0a7-94114c861d5a@redhat.com \
--to=maxime.coquelin@redhat.com \
--cc=chenbo.xia@intel.com \
--cc=dev@dpdk.org \
--cc=fengli@smartx.com \
--cc=mb@smartsharesystems.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).