From: Christian Borntraeger <borntraeger@linux.ibm.com>
To: Cornelia Huck <cohuck@redhat.com>
Cc: qemu-devel <qemu-devel@nongnu.org>,
qemu-s390x <qemu-s390x@nongnu.org>,
Halil Pasic <pasic@linux.ibm.com>,
Matthew Rosato <mjrosato@linux.ibm.com>,
Eric Farman <farman@linux.ibm.com>,
Christian Borntraeger <borntraeger@linux.ibm.com>,
Jason Herne <jjherne@linux.ibm.com>,
Richard Henderson <richard.henderson@linaro.org>,
Ilya Leoshkevich <iii@linux.ibm.com>,
David Hildenbrand <david@kernel.org>,
qemu-stable@nongnu.org
Subject: [PATCH 2/5] s390x/pci: Tighten region detection for BAR read/write
Date: Mon, 6 Jul 2026 11:19:06 +0200 [thread overview]
Message-ID: <20260706091909.864405-3-borntraeger@linux.ibm.com> (raw)
In-Reply-To: <20260706091909.864405-1-borntraeger@linux.ibm.com>
From: Matthew Rosato <mjrosato@linux.ibm.com>
For PCISTG/PCISTB/PCILG instruction emulation, ensure that the offset
and length provided by the guest does not overflow, and only return
a memory region when the specified offset+length combination matches
an existing subregion or the parent region.
Cc: qemu-stable@nongnu.org
Fixes: 4f6482bfe3 ("s390x/pci: search for subregion inside the BARs")
Reviewed-by: Christian Borntraeger <borntraeger@linux.ibm.com>
Signed-off-by: Matthew Rosato <mjrosato@linux.ibm.com>
---
hw/s390x/s390-pci-inst.c | 24 +++++++++++++++++++++++-
1 file changed, 23 insertions(+), 1 deletion(-)
diff --git a/hw/s390x/s390-pci-inst.c b/hw/s390x/s390-pci-inst.c
index 10066ca618..ef20f7645e 100644
--- a/hw/s390x/s390-pci-inst.c
+++ b/hw/s390x/s390-pci-inst.c
@@ -392,13 +392,22 @@ static int zpci_endian_swap(uint64_t *ptr, uint8_t len)
static MemoryRegion *s390_get_subregion(MemoryRegion *mr, uint64_t offset,
uint8_t len)
{
+ uint64_t last = offset + len;
MemoryRegion *subregion;
uint64_t subregion_size;
+ /*
+ * Ensure the region is valid, the calculated address cannot wrap and that
+ * it falls within this region.
+ */
+ if (!mr || offset > last || last > memory_region_size(mr)) {
+ return NULL;
+ }
+
QTAILQ_FOREACH(subregion, &mr->subregions, subregions_link) {
subregion_size = memory_region_size(subregion);
if ((offset >= subregion->addr) &&
- (offset + len) <= (subregion->addr + subregion_size)) {
+ (last) <= (subregion->addr + subregion_size)) {
mr = subregion;
break;
}
@@ -413,6 +422,10 @@ static MemTxResult zpci_read_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
mr = pbdev->pdev->io_regions[pcias].memory;
mr = s390_get_subregion(mr, offset, len);
+ if (!mr) {
+ return MEMTX_ERROR;
+ }
+
offset -= mr->addr;
return memory_region_dispatch_read(mr, offset, data,
size_memop(len) | MO_BE,
@@ -513,6 +526,10 @@ static MemTxResult zpci_write_bar(S390PCIBusDevice *pbdev, uint8_t pcias,
mr = pbdev->pdev->io_regions[pcias].memory;
mr = s390_get_subregion(mr, offset, len);
+ if (!mr) {
+ return MEMTX_ERROR;
+ }
+
offset -= mr->addr;
return memory_region_dispatch_write(mr, offset, data,
size_memop(len) | MO_BE,
@@ -900,6 +917,11 @@ int pcistb_service_call(S390CPU *cpu, uint8_t r1, uint8_t r3, uint64_t gaddr,
mr = pbdev->pdev->io_regions[pcias].memory;
mr = s390_get_subregion(mr, offset, len);
+ if (!mr) {
+ s390_program_interrupt(env, PGM_OPERAND, ra);
+ return 0;
+ }
+
offset -= mr->addr;
for (i = 0; i < len; i += 8) {
--
2.53.0
next prev parent reply other threads:[~2026-07-06 9:23 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-06 9:19 [PATCH 0/5] s390x: interface hardening fixes Christian Borntraeger
2026-07-06 9:19 ` [PATCH 1/5] s390x/sclp: reject invalid write event data headers Christian Borntraeger
2026-07-06 13:12 ` Matthew Rosato
2026-07-07 1:28 ` Eric Farman
2026-07-07 6:05 ` Philippe Mathieu-Daudé
2026-07-06 9:19 ` Christian Borntraeger [this message]
2026-07-06 19:09 ` [PATCH 2/5] s390x/pci: Tighten region detection for BAR read/write Farhan Ali
2026-07-06 9:19 ` [PATCH 3/5] s390x/pci: Shrink RPCIT ranges to registered window Christian Borntraeger
2026-07-06 19:07 ` Farhan Ali
2026-07-06 9:19 ` [PATCH 4/5] s390x/ioinst: Require strict length and format for SEI CHSC handler Christian Borntraeger
2026-07-06 19:08 ` Farhan Ali
2026-07-07 1:30 ` Eric Farman
2026-07-06 9:19 ` [PATCH 5/5] s390x/css: limit number of CHPIDs in description Christian Borntraeger
2026-07-06 17:49 ` Matthew Rosato
2026-07-06 15:13 ` [PATCH 0/5] s390x: interface hardening fixes Cornelia Huck
2026-07-06 16:31 ` Christian Borntraeger
2026-07-07 6:54 ` Cornelia Huck
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=20260706091909.864405-3-borntraeger@linux.ibm.com \
--to=borntraeger@linux.ibm.com \
--cc=cohuck@redhat.com \
--cc=david@kernel.org \
--cc=farman@linux.ibm.com \
--cc=iii@linux.ibm.com \
--cc=jjherne@linux.ibm.com \
--cc=mjrosato@linux.ibm.com \
--cc=pasic@linux.ibm.com \
--cc=qemu-devel@nongnu.org \
--cc=qemu-s390x@nongnu.org \
--cc=qemu-stable@nongnu.org \
--cc=richard.henderson@linaro.org \
/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.