From: "Michael S. Tsirkin" <mst@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>, qemu-devel@nongnu.org
Cc: 李强 <liqiang6-s@360.cn>,
"pmatouse@redhat.com" <pmatouse@redhat.com>,
"sstabellini@kernel.org" <sstabellini@kernel.org>,
"secalert@redhat.com" <secalert@redhat.com>,
"mdroth@linux.vnet.ibm.com" <mdroth@linux.vnet.ibm.com>,
g-sec-cloud <g-sec-cloud@list.qihoo.net>
Subject: [Qemu-devel] [PATCH] cadence_uart: bounds check write offset
Date: Mon, 18 Apr 2016 13:07:35 +0300 [thread overview]
Message-ID: <20160418100735.GA517@redhat.com> (raw)
In-Reply-To: <143C0AFC63FC204CB0C55BB88F3A8ABBE31B34@EX01.corp.qihoo.net>
cadence_uart_init() initializes an I/O memory region of size 0x1000
bytes. However in uart_write(), the 'offset' parameter (offset within
region) is divided by 4 and then used to index the array 'r' of size
CADENCE_UART_R_MAX which is much smaller: (0x48/4). If 'offset>>=2'
exceeds CADENCE_UART_R_MAX, this will cause an out-of-bounds memory
write where the offset and the value are controlled by guest.
This will corrupt QEMU memory, in most situations this causes the vm to
crash.
Fix by checking the offset against the array size.
Reported-by: 李强 <liqiang6-s@360.cn>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
---
diff --git a/hw/char/cadence_uart.c b/hw/char/cadence_uart.c
index 486591b..7977878 100644
--- a/hw/char/cadence_uart.c
+++ b/hw/char/cadence_uart.c
@@ -375,6 +375,9 @@ static void uart_write(void *opaque, hwaddr offset,
DB_PRINT(" offset:%x data:%08x\n", (unsigned)offset, (unsigned)value);
offset >>= 2;
+ if (offset >= CADENCE_UART_R_MAX) {
+ return;
+ }
switch (offset) {
case R_IER: /* ier (wts imr) */
s->r[R_IMR] |= value;
next parent reply other threads:[~2016-04-18 10:07 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <RT-Ticket-398672@engineering.redhat.com>
[not found] ` <143C0AFC63FC204CB0C55BB88F3A8ABBE31B34@EX01.corp.qihoo.net>
2016-04-18 10:07 ` Michael S. Tsirkin [this message]
2016-04-18 10:10 ` [Qemu-devel] [PATCH] cadence_uart: bounds check write offset Peter Maydell
2016-04-18 20:50 ` Alistair Francis
2016-04-19 10:15 ` Peter Maydell
[not found] ` <20160418081029.GA30482@redhat.com>
[not found] ` <CAFEAcA9zNW-hdTW4wK9vjCcmAjDKAcfQA+DNKra-jS2d=TLxLQ@mail.gmail.com>
[not found] ` <20160418120139-mutt-send-email-mst@redhat.com>
[not found] ` <143C0AFC63FC204CB0C55BB88F3A8ABBE35B0E@EX01.corp.qihoo.net>
[not found] ` <20160418122728-mutt-send-email-mst@redhat.com>
[not found] ` <143C0AFC63FC204CB0C55BB88F3A8ABBE36DC7@EX01.corp.qihoo.net>
2016-04-29 13:08 ` [Qemu-devel] [engineering.redhat.com #398672] [QEMU-SECURITY] Out-of-bands write in uart_write() Red Hat Product Security
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=20160418100735.GA517@redhat.com \
--to=mst@redhat.com \
--cc=g-sec-cloud@list.qihoo.net \
--cc=liqiang6-s@360.cn \
--cc=mdroth@linux.vnet.ibm.com \
--cc=peter.maydell@linaro.org \
--cc=pmatouse@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=secalert@redhat.com \
--cc=sstabellini@kernel.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.