From: Zheng Huang <hz1624917200@gmail.com>
To: qemu-devel@nongnu.org
Subject: [PATCH] hw/scsi/esp: fix assertion error in fifo8_push
Date: Tue, 27 May 2025 21:12:26 +0800 [thread overview]
Message-ID: <37889706-8576-476c-8fea-c1a3a2858b1e@gmail.com> (raw)
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.
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]);
}
}
--
2.34.1
next reply other threads:[~2025-05-27 13:13 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-27 13:12 Zheng Huang [this message]
2025-05-27 13:59 ` [PATCH] hw/scsi/esp: fix assertion error in fifo8_push 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
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=37889706-8576-476c-8fea-c1a3a2858b1e@gmail.com \
--to=hz1624917200@gmail.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).