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
Subject: [PATCH v2 3/3] spapr: nested: Reject zero length buffer in H_GUEST_{GET, SET}_STATE
Date: Mon, 30 Nov 2026 16:18:50 +0530 [thread overview]
Message-ID: <20261130104850.190510-4-uverma@linux.ibm.com> (raw)
In-Reply-To: <20261130104850.190510-1-uverma@linux.ibm.com>
From: Amit Machhiwal <amachhiw@linux.ibm.com>
PAPR requires H_GUEST_GET_STATE and H_GUEST_SET_STATE to return H_P5
when dataBufferSizeInBytes is 0. QEMU does not check for it, and
address_space_map() returns NULL for a zero length.
map_and_getset_state() then jumps to out1 and calls
address_space_unmap() on the NULL pointer, so an L1 guest that passes
buflen = 0 crashes QEMU:
Program received signal SIGSEGV, Segmentation fault.
#0 address_space_unmap (buffer=0x0, len=0, ...) at system/physmem.c:3847
#1 map_and_getset_state (...) at hw/ppc/spapr_nested.c:1536
#2 h_guest_getset_state (...) at hw/ppc/spapr_nested.c:1592
Return H_P5 for a zero length together with the existing upper bound
check. Also return directly when address_space_map() fails for any
other reason, as there is nothing to unmap.
Fixes: 64c43909b297 ("spapr: nested: Introduce H_GUEST_[GET|SET]_STATE hcalls.")
Cc: qemu-stable@nongnu.org
Signed-off-by: Amit Machhiwal <amachhiw@linux.ibm.com>
---
hw/ppc/spapr_nested.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hw/ppc/spapr_nested.c b/hw/ppc/spapr_nested.c
index b636da8dd0..ee922bb133 100644
--- a/hw/ppc/spapr_nested.c
+++ b/hw/ppc/spapr_nested.c
@@ -1549,7 +1549,7 @@ static target_ulong map_and_getset_state(PowerPCCPU *cpu,
} else {
rc = H_P4;
}
- goto out1;
+ return rc;
}
if (len != gsr->len) {
@@ -1582,7 +1582,7 @@ static target_ulong h_guest_getset_state(PowerPCCPU *cpu,
SpaprMachineStateNestedGuest *guest = NULL;
gsr.buf = buf;
- if (buflen > GSB_MAX_BUF_SIZE) {
+ if (buflen == 0 || buflen > GSB_MAX_BUF_SIZE) {
return H_P5;
}
gsr.len = buflen;
--
2.55.0
prev parent reply other threads:[~2026-11-30 10:50 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 ` [PATCH v2 1/3] spapr: nested: Check guest state buffer len " Utkarsh Verma
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 ` Utkarsh Verma [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=20261130104850.190510-4-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.