From: Zheng Huang <hz1624917200@gmail.com>
To: "Mark Cave-Ayland" <mark.cave-ayland@ilande.co.uk>,
"Philippe Mathieu-Daudé" <philmd@linaro.org>,
qemu-devel@nongnu.org
Cc: Paolo Bonzini <pbonzini@redhat.com>, Fam Zheng <fam@euphon.net>,
Peter Xu <peterx@redhat.com>, Fabiano Rosas <farosas@suse.de>,
peter.maydell@linaro.org
Subject: Re: [PATCH] hw/scsi/esp: fix assertion error in fifo8_push
Date: Wed, 28 May 2025 13:54:36 +0800 [thread overview]
Message-ID: <7adc70a2-e99f-42c5-825c-901554e91d1b@gmail.com> (raw)
In-Reply-To: <6dd914b1-2a2f-4a4c-bd2b-54e8302d1a75@ilande.co.uk>
On 2025/5/28 03:40, Mark Cave-Ayland wrote:
> On 27/05/2025 14:59, Philippe Mathieu-Daudé wrote:
>
>> Hi,
>>
>> Cc'ing maintainers:
>>
>> $ ./scripts/get_maintainer.pl -f hw/scsi/esp.c
>> Paolo Bonzini <pbonzini@redhat.com> (supporter:SCSI)
>> Fam Zheng <fam@euphon.net> (reviewer:SCSI)
>> $ ./scripts/get_maintainer.pl -f migration/
>> Peter Xu <peterx@redhat.com> (maintainer:Migration)
>> Fabiano Rosas <farosas@suse.de> (maintainer:Migration)
>>
>> On 27/5/25 15:12, Zheng Huang wrote:
>>> This patch add validation checks on FIFO structures in esp_post_load() to
>>> avoid assertion error `assert(fifo->num < fifo->capacity);` in fifo8_push(),
>>> which can occur if the inbound migration stream is malformed. By performing
>>> these checks during post-load, we can catch and handle such issues earlier,
>>> avoiding crashes due to corrupted state.
>>
>> How can that happen? Can you share a reproducer?
>>
>>>
>>> Signed-off-by: Zheng Huang <hz1624917200@gmail.com>
>>> ---
>>> hw/scsi/esp.c | 6 ++++++
>>> 1 file changed, 6 insertions(+)
>>>
>>> diff --git a/hw/scsi/esp.c b/hw/scsi/esp.c
>>> index ac841dc32e..ba77017087 100644
>>> --- a/hw/scsi/esp.c
>>> +++ b/hw/scsi/esp.c
>>> @@ -1350,11 +1350,17 @@ static int esp_post_load(void *opaque, int version_id)
>>> /* Migrate ti_buf to fifo */
>>> len = s->mig_ti_wptr - s->mig_ti_rptr;
>>> for (i = 0; i < len; i++) {
>>> + if (&s->fifo.num >= &s->fifo.capacity) {
>>> + return -1;
>>> + }
>>> fifo8_push(&s->fifo, s->mig_ti_buf[i]);
>>> }
>>> /* Migrate cmdbuf to cmdfifo */
>>> for (i = 0; i < s->mig_cmdlen; i++) {
>>> + if (&s->cmdfifo.num >= &s->cmdfifo.capacity) {
>>> + return -1;
>>> + }
>>> fifo8_push(&s->cmdfifo, s->mig_cmdbuf[i]);
>>> }
>>> }
>
> This seems odd: this logic in esp_post_load() is for converting from pre-Fifo8 code to the current Fifo8 code, so why wouldn't we want to assert() for the case when the migration stream is intentionally malformed? Is there a case whereby the old code could generate an invalid migration stream like this?
>
>
> ATB,
>
> Mark.
>
Hi Mark,
The malformed migration stream in question originates from QEMU itself—either accidentally, due to
a bug, or maliciously crafted. If we allow unchecked data through in esp_post_load(), an attacker
controlling the migration source could send crafted values that trigger undefined behavior.
The commit https://gitlab.com/qemu-project/qemu/-/commit/b88cfee90268cad376682da8f99ccf024d7aa304
also check the migration stream integrity in post_load handler, which is suggested by Peter Maydell in
https://lists.gnu.org/archive/html/qemu-devel/2024-07/msg00099.html, 'to prevent the division-by-zero
in the "malicious inbound migration state" case'.
Also, I would appreciate your opinion on how we should handle such "malformed migration stream" case
more generally, if there are more severe issues than assertion error, such as FPE, UAF, etc.? Should
QEMU adopt a more systematic “post_load” validation pattern—verifying all critical fields across every
migration handler—to harden the migration subsystem against any tampering of the migration image?
Best regards,
Zheng.
prev parent reply other threads:[~2025-05-28 5:55 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 13:12 [PATCH] hw/scsi/esp: fix assertion error in fifo8_push Zheng Huang
2025-05-27 13:59 ` Philippe Mathieu-Daudé
2025-05-27 19:40 ` Mark Cave-Ayland
2025-05-28 5:51 ` Zheng Huang
2025-05-28 13:07 ` Fabiano Rosas
2025-05-29 9:38 ` Zheng Huang
2025-05-28 5:54 ` Zheng Huang [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=7adc70a2-e99f-42c5-825c-901554e91d1b@gmail.com \
--to=hz1624917200@gmail.com \
--cc=fam@euphon.net \
--cc=farosas@suse.de \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@linaro.org \
--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).