From: Luigi Leonardi <leonardi@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Ani Sinha <anisinha@redhat.com>,
Luigi Leonardi <leonardi@redhat.com>
Subject: [PATCH 1/2] igvm: honor byte_offset when writing memory map, MADT and device tree
Date: Wed, 02 Sep 2026 16:21:58 +0200 [thread overview]
Message-ID: <20260902-fix_offset-v1-1-04b18f7595b2@redhat.com> (raw)
In-Reply-To: <20260902-fix_offset-v1-0-04b18f7595b2@redhat.com>
qigvm_directive_memory_map(), qigvm_directive_madt() and
qigvm_directive_device_tree() all wrote their data unconditionally at
the start of the parameter area's buffer, ignoring param->byte_offset
from the IGVM_VHS_PARAMETER header. This is harmless when a
directive's offset happens to be 0, but breaks for IGVM files that pack
multiple parameters into a single shared parameter area at different
offsets: a later directive would overwrite the data written by an earlier
one at the start of the buffer, corrupting it.
Use param_entry->data + param->byte_offset as the write location and
size the bounds checks against the remaining space in the buffer
rather than its full size.
Signed-off-by: Luigi Leonardi <leonardi@redhat.com>
---
backends/igvm.c | 10 ++++++----
target/i386/igvm.c | 4 ++--
2 files changed, 8 insertions(+), 6 deletions(-)
diff --git a/backends/igvm.c b/backends/igvm.c
index 7b7bdc72b7..a6e3a58022 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -632,8 +632,10 @@ static int qigvm_directive_memory_map(QIgvm *ctx, const uint8_t *header_data,
return -1;
}
- max_entry_count = param_entry->size / sizeof(IGVM_VHS_MEMORY_MAP_ENTRY);
- mm_entry = (IGVM_VHS_MEMORY_MAP_ENTRY *)param_entry->data;
+ max_entry_count = (param_entry->size - param->byte_offset) /
+ sizeof(IGVM_VHS_MEMORY_MAP_ENTRY);
+ mm_entry = (IGVM_VHS_MEMORY_MAP_ENTRY *)(param_entry->data +
+ param->byte_offset);
retval = get_mem_map_entry(entry, &cgmm_entry, errp);
while (retval == 0) {
@@ -837,14 +839,14 @@ static int qigvm_directive_device_tree(QIgvm *ctx, const uint8_t *header_data,
}
fdt_size = fdt_totalsize(fdt_packed);
- if (fdt_size > param_entry->size) {
+ if (fdt_size > param_entry->size - param->byte_offset) {
error_setg(errp,
"IGVM: device tree size exceeds parameter area"
" defined in IGVM file");
return -1;
}
- memcpy(param_entry->data, fdt_packed, fdt_size);
+ memcpy(param_entry->data + param->byte_offset, fdt_packed, fdt_size);
return 0;
}
diff --git a/target/i386/igvm.c b/target/i386/igvm.c
index ad9bf87761..4d9d97385a 100644
--- a/target/i386/igvm.c
+++ b/target/i386/igvm.c
@@ -199,8 +199,8 @@ int qigvm_directive_madt(QIgvm *ctx, const uint8_t *header_data, Error **errp)
GArray *madt = acpi_build_madt_standalone(ctx->machine_state);
- if (madt->len <= param_entry->size) {
- memcpy(param_entry->data, madt->data, madt->len);
+ if (madt->len <= param_entry->size - param->byte_offset) {
+ memcpy(param_entry->data + param->byte_offset, madt->data, madt->len);
} else {
error_setg(
errp,
--
2.55.0
next prev parent reply other threads:[~2026-09-02 14:22 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-02 14:21 [PATCH 0/2] igvm: fix byte_offset handling in parameter directives Luigi Leonardi
2026-09-02 14:21 ` Luigi Leonardi [this message]
2026-09-02 14:43 ` [PATCH 1/2] igvm: honor byte_offset when writing memory map, MADT and device tree Stefano Garzarella
2026-09-02 14:21 ` [PATCH 2/2] igvm: validate byte_offset before using it in parameter directives Luigi Leonardi
2026-09-02 14:56 ` 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=20260902-fix_offset-v1-1-04b18f7595b2@redhat.com \
--to=leonardi@redhat.com \
--cc=anisinha@redhat.com \
--cc=kraxel@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=sgarzare@redhat.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 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.