From: Harsh Prateek Bora <harshpb@linux.ibm.com>
To: qemu-devel@nongnu.org
Cc: Chinmay Rath <rathc@linux.ibm.com>,
Guthrie McAfee Armstrong <git@gmarmstrong.dev>,
Gautam Menghani <gautam@linux.ibm.com>
Subject: [PULL 6/6] spapr-vscsi: clamp adapter info DMA write length to struct size
Date: Wed, 28 Oct 2026 10:50:24 +0530 [thread overview]
Message-ID: <20261028052024.38377-7-harshpb@linux.ibm.com> (raw)
In-Reply-To: <20261028052024.38377-1-harshpb@linux.ibm.com>
From: Chinmay Rath <rathc@linux.ibm.com>
vscsi_send_adapter_info() used the guest-supplied common.length
field directly as the size argument to spapr_vio_dma_write().
Since common.length is controlled by the guest, a value larger
than sizeof(struct mad_adapter_info_data) (148 bytes) caused
dma_memory_write() to read past the end of the stack-allocated info
struct, leaking arbitrary host stack contents into guest memory.
Fix this by clamping the write length to sizeof(info), then using
spapr_vio_dma_set() to zero-fill any remaining bytes the guest
requested beyond that size. This mirrors the existing pattern in
vscsi_send_capabilities().
Closes: https://gitlab.com/qemu-project/qemu/-/work_items/4626
Reported-by: Guthrie McAfee Armstrong <git@gmarmstrong.dev>
Signed-off-by: Chinmay Rath <rathc@linux.ibm.com>
Reviewed-by: Gautam Menghani <gautam@linux.ibm.com>
Tested-by: Gautam Menghani <gautam@linux.ibm.com>
Link: https://lore.kernel.org/qemu-devel/20261007144434.374749-1-rathc@linux.ibm.com
Signed-off-by: Harsh Prateek Bora <harshpb@linux.ibm.com>
---
hw/scsi/spapr_vscsi.c | 18 ++++++++++++++++--
1 file changed, 16 insertions(+), 2 deletions(-)
diff --git a/hw/scsi/spapr_vscsi.c b/hw/scsi/spapr_vscsi.c
index b4c8f94d22..7ec780da79 100644
--- a/hw/scsi/spapr_vscsi.c
+++ b/hw/scsi/spapr_vscsi.c
@@ -966,6 +966,8 @@ static int vscsi_send_adapter_info(VSCSIState *s, vscsi_req *req)
{
struct viosrp_adapter_info *sinfo;
struct mad_adapter_info_data info;
+ uint16_t len, req_len;
+ uint64_t buffer;
int rc;
sinfo = &req_iu(req)->mad.adapter_info;
@@ -985,11 +987,23 @@ static int vscsi_send_adapter_info(VSCSIState *s, vscsi_req *req)
info.os_type = cpu_to_be32(2);
info.port_max_txu[0] = cpu_to_be32(VSCSI_MAX_SECTORS << 9);
- rc = spapr_vio_dma_write(&s->vdev, be64_to_cpu(sinfo->buffer),
- &info, be16_to_cpu(sinfo->common.length));
+ req_len = len = be16_to_cpu(sinfo->common.length);
+ buffer = be64_to_cpu(sinfo->buffer);
+ if (len > sizeof(info)) {
+ fprintf(stderr, "vscsi_send_adapter_info: adapter info size mismatch !\n");
+ /*
+ * Just read and populate the structure that is known.
+ * Zero rest of the structure.
+ */
+ len = sizeof(info);
+ }
+ rc = spapr_vio_dma_write(&s->vdev, buffer, &info, len);
if (rc) {
fprintf(stderr, "vscsi_send_adapter_info: DMA write failure !\n");
}
+ if (req_len > len) {
+ spapr_vio_dma_set(&s->vdev, (buffer + len), 0, (req_len - len));
+ }
sinfo->common.status = rc ? cpu_to_be32(1) : 0;
--
2.52.0
next prev parent reply other threads:[~2026-10-28 5:21 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-28 5:20 [PULL 0/6] ppc queue for 2026-10-28 Harsh Prateek Bora
2026-10-28 5:20 ` [PULL 1/6] hw/pci-host/pnv_phb4: fix guest-triggerable abort on 8-byte config access Harsh Prateek Bora
2026-10-28 5:20 ` [PULL 2/6] tests/functional/ppc64: extend pseries migration tests Harsh Prateek Bora
2026-10-28 5:20 ` [PULL 3/6] tests/functional/ppc64: extend ppc64 powernv net device tests Harsh Prateek Bora
2026-10-28 5:20 ` [PULL 4/6] hw/net/spapr_llan: validate RxBufPool fields on migration load Harsh Prateek Bora
2026-10-28 5:20 ` [PULL 5/6] hw/ppc/spapr: Add the "rtas-version" property to /rtas Harsh Prateek Bora
2026-10-28 5:20 ` Harsh Prateek Bora [this message]
2026-10-28 11:20 ` [PULL 0/6] ppc queue for 2026-10-28 Richard Henderson
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=20261028052024.38377-7-harshpb@linux.ibm.com \
--to=harshpb@linux.ibm.com \
--cc=gautam@linux.ibm.com \
--cc=git@gmarmstrong.dev \
--cc=qemu-devel@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.