From: Stefano Garzarella <sgarzare@redhat.com>
To: Andrey Drobyshev <andrey.drobyshev@virtuozzo.com>
Cc: qemu-devel@nongnu.org, mst@redhat.com, farosas@suse.de,
peterx@redhat.com, dongli.zhang@oracle.com,
maciej.szmigiero@oracle.com, bchaney@akamai.com,
mark.kanda@oracle.com, den@openvz.org
Subject: Re: [PATCH v4 05/10] vhost-vsock: preserve vhost FD during CPR
Date: Mon, 14 Sep 2026 11:03:29 +0200 [thread overview]
Message-ID: <aqe3npSbJDwkeng9@sgarzare-redhat> (raw)
In-Reply-To: <1d7c8444-a566-48ae-8c62-4a5e1adf3528@virtuozzo.com>
On Fri, Sep 11, 2026 at 07:35:31PM +0300, Andrey Drobyshev wrote:
>On 9/11/26 10:37 AM, Stefano Garzarella wrote:
>> On Wed, Sep 09, 2026 at 07:59:55PM +0300, Andrey Drobyshev wrote:
>>> On 9/7/26 5:55 PM, Stefano Garzarella wrote:
>>>> On Thu, Aug 20, 2026 at 02:39:50PM +0300, Andrey Drobyshev wrote:
>>>>> During CPR (checkpoint-restore) migration the guest keeps running on the
>>>>> same host, so instead of reopening /dev/vhost-vsock on the destination,
>>>>> we should reuse the FD from the source. The FD is saved in the CPR
>>>>> namespace (hash table) with cpr_save_fd() and then reclaimed on the
>>>>> target via cpr_find_fd().
>>>>>
>>>>> Since the key in CPR hash table is device ID, CPR needs a unique ID.
>>>>
>>>> mm, are we sure the device ID is unique?
>>>>
>>>> I just tried this whitout receiving any error:
>>>> qemu-system-x86_64 -smp 2 -M q35,accel=kvm,memory-backend=vsock0 \
>>>> -object memory-backend-memfd,id=vsock0,size=512M \
>>>> -device vhost-vsock-pci,id=vsock0,guest-cid=3
>>>>
>>>> Stefano
>>> You're right, that seems to be the a real issue. In fact there's even a
>>> UAF bug IIUC, stemming from the fact that we: 1) provide key destroy
>>> function when creating the CPR hash table; 2) use same CprFd for both
>>> key and value.
>>>
>>> That means that when we have several devices supporting CPR with
>>> repeating IDs, we do:
>>>
>>> g_hash_table_insert(table, fd1, fd1); // table has fd1 -> fd1
>>> g_hash_table_insert(table, fd2, fd2); // table has fd1 -> fd2
>>>
>>> Here fd1 and fd2 have same hash of course. According to GLib docs [1],
>>> value is renewed in this case, but the new key is destroyed and the
>>> old
>>> one is used. As a result, fd2 is freed.
>>>
>>> And, mind you, this all happens long before actual CPR, cause the
>>> devices with CPR support usually call cpr_save_fd() somewhere in
>>> .realize(). Thus we get memory corruption right at boot time, plus
>>> subsequent CPR will likely crash.
>>>
>>> In these circumstances I'd personally prefer just asserting on repeating
>>> key somewhere in cpr_fd_hash_insert(). The only downside is that it'll
>>> crash when booting 2 CPR supporting devices having identical IDs, even
>>> if the user isn't going to perform CPR. I'd say it's acceptable, what
>>> do you think?
>>
>> I'd prefer an error if possible.
>>
>> That said, can we append a prefix to the key (e.g. `vhost-vsock`)?
>> In this way we reduce the chance to have a conflict. Of course the user
>> can still assign `vhost-vsock-something` to the memory backend and
>> `something` to the vhost-vsock device, but yeah xD
>>
>> Thanks,
>> Stefano
>>
>
>If you mean erroring out directly at startup whenever we encounter a
>duplicate CPR key, with a clear error message instead of abort/crash - I
>agree that it's a better solution.
Yep.
> That'll likely require changing the
>CPR FD saving API, but shouldn't be too intrusive. As for the prefix -
>once we forbid duplicate keys entirely, there's no need for it.
Agree, but not sure if this break some user that re-use the same id for
devices in different "namespaces" that will boot, but collide when doing
CPR. That said, no strong opinion here, maybe I'm overthinking.
Stefano
next prev parent reply other threads:[~2026-09-14 9:04 UTC|newest]
Thread overview: 36+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-08-20 11:39 [PATCH v4 00/10] migration/cpr: support vhost-vsock devices Andrey Drobyshev
2026-08-20 11:39 ` [PATCH v4 01/10] vhost-vsock: block CPR migration modes Andrey Drobyshev
2026-09-07 14:54 ` Stefano Garzarella
2026-08-20 11:39 ` [PATCH v4 02/10] vhost: add vhost_reset_owner op Andrey Drobyshev
2026-09-07 13:58 ` Stefano Garzarella
2026-09-09 16:59 ` Andrey Drobyshev
2026-08-20 11:39 ` [PATCH v4 03/10] vhost-vsock: don't reset connections during CPR Andrey Drobyshev
2026-09-07 14:54 ` Stefano Garzarella
2026-08-20 11:39 ` [PATCH v4 04/10] vhost-vsock: fix FD leak in realize() Andrey Drobyshev
2026-09-07 14:54 ` Stefano Garzarella
2026-09-09 16:59 ` Andrey Drobyshev
2026-08-20 11:39 ` [PATCH v4 05/10] vhost-vsock: preserve vhost FD during CPR Andrey Drobyshev
2026-09-07 14:55 ` Stefano Garzarella
2026-09-09 16:59 ` Andrey Drobyshev
2026-09-11 7:37 ` Stefano Garzarella
2026-09-11 16:35 ` Andrey Drobyshev
2026-09-14 9:03 ` Stefano Garzarella [this message]
2026-09-14 9:11 ` Andrey Drobyshev
2026-08-20 11:39 ` [PATCH v4 06/10] vhost: factor out vhost_dev_init_backend() Andrey Drobyshev
2026-09-07 14:55 ` Stefano Garzarella
2026-08-20 11:39 ` [PATCH v4 07/10] vhost: make vhost_dev_cleanup() safe on a partially initialized device Andrey Drobyshev
2026-09-07 14:56 ` Stefano Garzarella
2026-09-09 17:06 ` Andrey Drobyshev
2026-08-20 11:39 ` [PATCH v4 08/10] vhost: add vhost_dev_set_owner() / vhost_dev_reset_owner() helpers Andrey Drobyshev
2026-09-07 14:56 ` Stefano Garzarella
2026-09-09 17:05 ` Andrey Drobyshev
2026-08-20 11:39 ` [PATCH v4 09/10] vhost: add vhost_dev_is_initialized() helper Andrey Drobyshev
2026-09-07 14:57 ` Stefano Garzarella
2026-08-20 11:39 ` [PATCH v4 10/10] vhost-vsock: hand off device ownership across CPR Andrey Drobyshev
2026-09-07 15:13 ` Stefano Garzarella
2026-09-09 17:45 ` Andrey Drobyshev
2026-09-11 7:45 ` Stefano Garzarella
2026-09-11 16:35 ` Andrey Drobyshev
2026-09-14 9:07 ` Stefano Garzarella
2026-08-31 11:16 ` [PATCH v4 00/10] migration/cpr: support vhost-vsock devices Andrey Drobyshev
2026-09-07 10:07 ` Stefano Garzarella
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=aqe3npSbJDwkeng9@sgarzare-redhat \
--to=sgarzare@redhat.com \
--cc=andrey.drobyshev@virtuozzo.com \
--cc=bchaney@akamai.com \
--cc=den@openvz.org \
--cc=dongli.zhang@oracle.com \
--cc=farosas@suse.de \
--cc=maciej.szmigiero@oracle.com \
--cc=mark.kanda@oracle.com \
--cc=mst@redhat.com \
--cc=peterx@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.