From: Utkarsh Verma <uverma@linux.ibm.com>
To: qemu-devel@nongnu.org, qemu-ppc@nongnu.org
Cc: Chinmay Rath <rathc@linux.ibm.com>,
Harsh Prateek Bora <harshpb@linux.ibm.com>,
Amit Machhiwal <amachhiw@linux.ibm.com>,
Nicholas Piggin <npiggin@gmail.com>,
qemu-stable@nongnu.org, Utkarsh Verma <uverma@linux.ibm.com>
Subject: [PATCH v2 1/3] spapr: nested: Check guest state buffer len in H_GUEST_{GET, SET}_STATE
Date: Mon, 30 Nov 2026 16:18:48 +0530 [thread overview]
Message-ID: <20261130104850.190510-2-uverma@linux.ibm.com> (raw)
In-Reply-To: <20261130104850.190510-1-uverma@linux.ibm.com>
Add validations to check for guest state buffer length before accessing
the element header (id, size) and value fields to avoid out of bound
memory reads. Also, do the similar fix in log_element() function.
Fixes: 64c43909b297 ("spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls.")
Resolves: https://gitlab.com/qemu-project/qemu/-/work_items/4741
Cc: qemu-stable@nongnu.org
Signed-off-by: Utkarsh Verma <uverma@linux.ibm.com>
---
hw/ppc/spapr_nested.c | 16 +++++++++++++---
1 file changed, 13 insertions(+), 3 deletions(-)
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index 10cf634da1..35b5ae9785 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -1104,7 +1104,11 @@ static void log_element(struct guest_state_element *element,
qemu_log_mask(LOG_GUEST_ERROR, "h_guest_%s_state id:0x%04x size:0x%04x",
gsr->flags & GUEST_STATE_REQUEST_SET ? "set" : "get",
be16_to_cpu(element->id), be16_to_cpu(element->size));
- qemu_log_mask(LOG_GUEST_ERROR, "buf:0x%016"PRIx64" ...\n",
+ if (be16_to_cpu(element->size) < 8) {
+ qemu_log_mask(LOG_GUEST_ERROR, "\n");
+ return;
+ }
+ qemu_log_mask(LOG_GUEST_ERROR, " buf:0x%016"PRIx64" ...\n",
be64_to_cpu(*(uint64_t *)element->value));
}
@@ -1117,7 +1121,9 @@ static bool guest_state_request_check(struct guest_state_request *gsr)
uint16_t id, size;
/* gsb->num_elements = 0 == 32 bits long */
- assert(len >= 4);
+ if (len < (int64_t)sizeof(gsb->num_elements)) {
+ return false;
+ }
num_elements = be32_to_cpu(gsb->num_elements);
element = gsb->elements;
@@ -1126,6 +1132,9 @@ static bool guest_state_request_check(struct guest_state_request *gsr)
/* Walk the buffer to validate the length */
while (num_elements) {
+ if (len < (int64_t)offsetof(struct guest_state_element, value)) {
+ return false;
+ }
id = be16_to_cpu(element->id);
size = be16_to_cpu(element->size);
@@ -1133,7 +1142,8 @@ static bool guest_state_request_check(struct guest_state_request *gsr)
log_element(element, gsr);
}
/* buffer size too small */
- if (len < 0) {
+ if (len < (int64_t)(offsetof(struct guest_state_element, value) +
+ size)) {
return false;
}
--
2.55.0
next prev parent reply other threads:[~2026-11-30 10:49 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-30 10:48 [PATCH v2 0/3] spapr: nested: Fix OOB read and return codes in H_GUEST_{GET, SET}_STATE Utkarsh Verma
2026-11-30 10:48 ` Utkarsh Verma [this message]
2026-11-30 10:48 ` [PATCH v2 2/3] spapr: nested: Fix the return codes for H_GUEST_{GET, SET}_STATE and H_GUEST_RUN_VCPU Utkarsh Verma
2026-11-30 10:48 ` [PATCH v2 3/3] spapr: nested: Reject zero length buffer in H_GUEST_{GET, SET}_STATE Utkarsh Verma
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=20261130104850.190510-2-uverma@linux.ibm.com \
--to=uverma@linux.ibm.com \
--cc=amachhiw@linux.ibm.com \
--cc=harshpb@linux.ibm.com \
--cc=npiggin@gmail.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-ppc@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=rathc@linux.ibm.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.