From: "Cédric Le Goater" <clg@redhat.com>
To: qemu-arm@nongnu.org, qemu-devel@nongnu.org
Cc: "Cédric Le Goater" <clg@redhat.com>,
"Katherine Leaver" <katherine.j.leaver@gmail.com>,
qemu-stable@nongnu.org
Subject: [PULL 3/9] aspeed/hace: Prevent total_req_len overflow
Date: Tue, 12 May 2026 19:13:48 +0200 [thread overview]
Message-ID: <20260512171354.4183887-4-clg@redhat.com> (raw)
In-Reply-To: <20260512171354.4183887-1-clg@redhat.com>
In accumulate mode, total_req_len is incremented with plen (hwaddr)
for each hash request. Repeated additions can overflow total_req_len
(uint32_t) and potentially bypass validation checks in has_padding().
Add a helper function to detect overflow before incrementing
total_req_len and reject the request if overflow would occur.
Reported-by: Katherine Leaver <katherine.j.leaver@gmail.com>
Cc: qemu-stable@nongnu.org
Fixes: 5cd7d8564a8b ("aspeed/hace: Support AST2600 HACE")
Link: https://lore.kernel.org/qemu-devel/20260504213421.710035-3-clg@redhat.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
---
hw/misc/aspeed_hace.c | 21 +++++++++++++++++++--
1 file changed, 19 insertions(+), 2 deletions(-)
diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c
index ef698b3ecb72..0504d61cbf0a 100644
--- a/hw/misc/aspeed_hace.c
+++ b/hw/misc/aspeed_hace.c
@@ -205,6 +205,19 @@ static uint64_t hash_get_source_addr(AspeedHACEState *s)
return src_addr;
}
+static bool hash_accumulate_len(AspeedHACEState *s, hwaddr plen)
+{
+ if (plen > UINT32_MAX - s->total_req_len) {
+ qemu_log_mask(LOG_GUEST_ERROR,
+ "%s: total_req_len overflow, current=0x%x, adding=0x%"
+ HWADDR_PRIx "\n", __func__, s->total_req_len, plen);
+ return false;
+ }
+
+ s->total_req_len += plen;
+ return true;
+}
+
static int hash_prepare_direct_iov(AspeedHACEState *s, struct iovec *iov,
bool acc_mode, bool *acc_final_request)
{
@@ -232,7 +245,9 @@ static int hash_prepare_direct_iov(AspeedHACEState *s, struct iovec *iov,
iov_idx = 1;
if (acc_mode) {
- s->total_req_len += plen;
+ if (!hash_accumulate_len(s, plen)) {
+ return -1;
+ }
if (has_padding(s, &iov[0], plen, &total_msg_len,
&pad_offset)) {
@@ -299,7 +314,9 @@ static int hash_prepare_sg_iov(AspeedHACEState *s, struct iovec *iov,
iov[iov_idx].iov_base = haddr;
if (acc_mode) {
- s->total_req_len += plen;
+ if (!hash_accumulate_len(s, plen)) {
+ return -1;
+ }
if (has_padding(s, &iov[iov_idx], plen, &total_msg_len,
&pad_offset)) {
--
2.54.0
next prev parent reply other threads:[~2026-05-12 17:15 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-12 17:13 [PULL 0/9] aspeed queue Cédric Le Goater
2026-05-12 17:13 ` [PULL 1/9] hw/misc/aspeed_sbc: Add bounds checking for OTP write operations Cédric Le Goater
2026-05-12 17:13 ` [PULL 2/9] aspeed/hace: Fix out-of-bounds read in has_padding() Cédric Le Goater
2026-05-12 17:13 ` Cédric Le Goater [this message]
2026-05-12 17:13 ` [PULL 4/9] aspeed/hace: Fix mapped address may not be unmapped issue Cédric Le Goater
2026-05-12 17:13 ` [PULL 5/9] hw/arm: Remove sonorapass-bmc machine Cédric Le Goater
2026-05-12 17:13 ` [PULL 6/9] hw/arm: Remove qcom-dc-scm-v1-bmc and qcom-firework-bmc machines Cédric Le Goater
2026-05-12 17:13 ` [PULL 7/9] hw/arm: Remove fp5280g2-bmc machine Cédric Le Goater
2026-05-12 17:13 ` [PULL 8/9] hw/arm: Remove fby35 machine Cédric Le Goater
2026-05-12 17:13 ` [PULL 9/9] hw/i3c/dw-i3c: Fix BCR/DCR extraction and PID assembly during ENTDAA Cédric Le Goater
2026-05-14 16:26 ` [PULL 0/9] aspeed queue Stefan Hajnoczi
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=20260512171354.4183887-4-clg@redhat.com \
--to=clg@redhat.com \
--cc=katherine.j.leaver@gmail.com \
--cc=qemu-arm@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=qemu-stable@nongnu.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.