From: Oliver Steffen <osteffen@redhat.com>
To: qemu-devel@nongnu.org
Cc: Gerd Hoffmann <kraxel@redhat.com>,
Ani Sinha <anisinha@redhat.com>,
Luigi Leonardi <leonardi@redhat.com>,
Stefano Garzarella <sgarzare@redhat.com>,
Oliver Steffen <osteffen@redhat.com>
Subject: [PATCH v2] igvm: Add NULL checks for igvm_get_buffer()
Date: Thu, 12 Feb 2026 16:41:14 +0100 [thread overview]
Message-ID: <20260212154114.1119944-1-osteffen@redhat.com> (raw)
According to the documentation we are supposed to do a null-pointer
check on the buffers returned by igvm_get_buffer() (part of the IGVM C
library).
Add these checks in the IGVM backend.
Signed-off-by: Oliver Steffen <osteffen@redhat.com>
---
backends/igvm.c | 37 +++++++++++++++++++++++++++++++------
1 file changed, 31 insertions(+), 6 deletions(-)
diff --git a/backends/igvm.c b/backends/igvm.c
index b01a19ba46..3b5edf1521 100644
--- a/backends/igvm.c
+++ b/backends/igvm.c
@@ -152,9 +152,17 @@ static int qigvm_handler(QIgvm *ctx, uint32_t type, Error **errp)
(int)header_handle);
return -1;
}
- header_data = igvm_get_buffer(ctx->file, header_handle) +
- sizeof(IGVM_VHS_VARIABLE_HEADER);
- result = handlers[handler].handler(ctx, header_data, errp);
+ header_data = igvm_get_buffer(ctx->file, header_handle);
+ if (header_data != NULL) {
+ header_data += sizeof(IGVM_VHS_VARIABLE_HEADER);
+ result = handlers[handler].handler(ctx, header_data, errp);
+ } else {
+ error_setg(errp,
+ "IGVM: No buffer for handle %d: "
+ "(type 0x%X)",
+ header_handle, type);
+ result = -1;
+ }
igvm_free_buffer(ctx->file, header_handle);
return result;
}
@@ -316,6 +324,11 @@ static int qigvm_process_mem_region(QIgvm *ctx, unsigned start_index,
return -1;
}
data = igvm_get_buffer(ctx->file, data_handle);
+ if (data == NULL) {
+ error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
+ igvm_free_buffer(ctx->file, data_handle);
+ return -1;
+ }
memcpy(®ion[page_index * page_size], data, data_size);
igvm_free_buffer(ctx->file, data_handle);
}
@@ -426,6 +439,11 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
}
data = (uint8_t *)igvm_get_buffer(ctx->file, data_handle);
+ if (data == NULL) {
+ error_setg(errp, "IGVM: No buffer for handle %d", data_handle);
+ result = -1;
+ goto exit;
+ }
if (ctx->machine_state->cgs) {
result = ctx->cgsc->set_guest_state(
@@ -441,6 +459,7 @@ static int qigvm_directive_vp_context(QIgvm *ctx, const uint8_t *header_data,
result = -1;
}
+exit:
igvm_free_buffer(ctx->file, data_handle);
if (result < 0) {
return result;
@@ -778,9 +797,15 @@ static int qigvm_supported_platform_compat_mask(QIgvm *ctx, Error **errp)
}
platform =
(IGVM_VHS_SUPPORTED_PLATFORM *)(igvm_get_buffer(ctx->file,
- header_handle) +
- sizeof(
- IGVM_VHS_VARIABLE_HEADER));
+ header_handle));
+ if (platform == NULL) {
+ error_setg(errp, "IGVM: No buffer for handle %d", header_handle);
+ igvm_free_buffer(ctx->file, header_handle);
+ return -1;
+ }
+
+ platform = (IGVM_VHS_SUPPORTED_PLATFORM *)((void *)platform
+ + sizeof(IGVM_VHS_VARIABLE_HEADER));
if ((platform->platform_type == IGVM_PLATFORM_TYPE_SEV_ES) &&
ctx->machine_state->cgs) {
if (ctx->cgsc->check_support(
--
2.53.0
next reply other threads:[~2026-02-12 15:41 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-12 15:41 Oliver Steffen [this message]
2026-02-13 9:20 ` [PATCH v2] igvm: Add NULL checks for igvm_get_buffer() Luigi Leonardi
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=20260212154114.1119944-1-osteffen@redhat.com \
--to=osteffen@redhat.com \
--cc=anisinha@redhat.com \
--cc=kraxel@redhat.com \
--cc=leonardi@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.