mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: redacherkaoui <redacherkaoui67@gmail.com>
To: pbonzini@redhat.com
Cc: kvm@vger.kernel.org, linux-kernel@vger.kernel.org,
	redahack12-glitch <redahack12@gmail.com>,
	REDA CHERKAOUI <redacherkaoui67@gmail.com>
Subject: [PATCH] KVM: coalesced_mmio: Fix out-of-bounds write in coalesced_mmio_write()
Date: Thu, 27 Nov 2025 01:11:32 +0100	[thread overview]
Message-ID: <20251127001132.13704-1-redacherkaoui67@gmail.com> (raw)

From: redahack12-glitch <redahack12@gmail.com>

The coalesced MMIO ring stores each entry's MMIO payload in an 8-byte
fixed-size buffer (data[8]). However, coalesced_mmio_write() copies
the payload using memcpy(..., len) without verifying that 'len' does not
exceed the buffer size.

A malicious or buggy caller could therefore trigger a write past the end
of the data[] array and corrupt adjacent kernel memory inside the ring
page.

Add a bounds check to reject writes where len > sizeof(data).

Signed-off-by: REDA CHERKAOUI <redacherkaoui67@gmail.com>
---
 virt/kvm/coalesced_mmio.c | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/virt/kvm/coalesced_mmio.c b/virt/kvm/coalesced_mmio.c
index 375d6285475e..4f302713de9e 100644
--- a/virt/kvm/coalesced_mmio.c
+++ b/virt/kvm/coalesced_mmio.c
@@ -68,6 +68,14 @@ static int coalesced_mmio_write(struct kvm_vcpu *vcpu,
 
 	/* copy data in first free entry of the ring */
 
+	/* Prevent overflow of the fixed 8-byte data[] field */
+	if (len > sizeof(ring->coalesced_mmio[insert].data)) {
+		spin_unlock(&dev->kvm->ring_lock);
+		pr_warn_ratelimited("KVM: coalesced MMIO write too large (%d > %zu)\n",
+				    len, sizeof(ring->coalesced_mmio[insert].data));
+		return -E2BIG;
+	}
+
 	ring->coalesced_mmio[insert].phys_addr = addr;
 	ring->coalesced_mmio[insert].len = len;
 	memcpy(ring->coalesced_mmio[insert].data, val, len);
-- 
2.43.0


             reply	other threads:[~2025-11-27  0:11 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-11-27  0:11 redacherkaoui [this message]
2025-12-01 19:03 ` Sean Christopherson

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=20251127001132.13704-1-redacherkaoui67@gmail.com \
    --to=redacherkaoui67@gmail.com \
    --cc=kvm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=redahack12@gmail.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®