From: Eric Auger <eric.auger@redhat.com>
To: Jason Wang <jasowang@redhat.com>
Cc: eric.auger.pro@gmail.com, mst@redhat.com, qemu-devel@nongnu.org,
lvivier@redhat.com
Subject: Re: [PATCH] vhost: Add a defensive check in vhost_commit against wrong deallocation
Date: Thu, 14 Sep 2023 09:45:00 +0200 [thread overview]
Message-ID: <ff2fd1c8-f894-fb4b-fa21-323698ab352a@redhat.com> (raw)
In-Reply-To: <CACGkMEttFn3eBfTPeumtfLuWnhZs7_4zKh6fP1jzyAb47GuQkQ@mail.gmail.com>
Hi Jason,
On 9/14/23 05:46, Jason Wang wrote:
> On Wed, Sep 13, 2023 at 3:47 PM Eric Auger <eric.auger@redhat.com> wrote:
>> In vhost_commit(), it may happen that dev->mem_sections and
>> dev->tmp_sections are equal, in which case, unconditionally
>> freeing old_sections at the end of the function will also free
>> dev->mem_sections used on subsequent call leading to a segmentation
>> fault.
>>
>> Check this situation before deallocating memory.
>>
>> Signed-off-by: Eric Auger <eric.auger@redhat.com>
>> Fixes: c44317efecb2 ("vhost: Build temporary section list and deref
>> after commit")
>> CC: QEMU Stable <qemu-stable@nongnu.org>
>>
>> ---
>>
>> This SIGSEV condition can be reproduced with
>> https://lore.kernel.org/all/20230904080451.424731-1-eric.auger@redhat.com/#r
>> This is most probably happening in a situation where the memory API is
>> used in a wrong manner but well.
> Any chance to move this to the memory API or we may end up with things
> like this in another listener?
I am not very familiar with the vhost code but aren't those tmp_sections
and mem_sections really specific to the vhost device? I am not sure we
can easily generalize.
Thanks
Eric
>
> Thanks
>
>> ---
>> hw/virtio/vhost.c | 5 +++++
>> 1 file changed, 5 insertions(+)
>>
>> diff --git a/hw/virtio/vhost.c b/hw/virtio/vhost.c
>> index e2f6ffb446..c02c599ef0 100644
>> --- a/hw/virtio/vhost.c
>> +++ b/hw/virtio/vhost.c
>> @@ -545,6 +545,11 @@ static void vhost_commit(MemoryListener *listener)
>> dev->mem_sections = dev->tmp_sections;
>> dev->n_mem_sections = dev->n_tmp_sections;
>>
>> + if (old_sections == dev->mem_sections) {
>> + assert(n_old_sections == dev->n_mem_sections);
>> + return;
>> + }
>> +
>> if (dev->n_mem_sections != n_old_sections) {
>> changed = true;
>> } else {
>> --
>> 2.41.0
>>
next prev parent reply other threads:[~2023-09-14 7:45 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-09-13 7:46 [PATCH] vhost: Add a defensive check in vhost_commit against wrong deallocation Eric Auger
2023-09-14 3:46 ` Jason Wang
2023-09-14 7:45 ` Eric Auger [this message]
2023-10-03 12:43 ` Michael S. Tsirkin
2023-10-03 13:16 ` Eric Auger
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=ff2fd1c8-f894-fb4b-fa21-323698ab352a@redhat.com \
--to=eric.auger@redhat.com \
--cc=eric.auger.pro@gmail.com \
--cc=jasowang@redhat.com \
--cc=lvivier@redhat.com \
--cc=mst@redhat.com \
--cc=qemu-devel@nongnu.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).