diff options
author | Jamin Lin <jamin_lin@aspeedtech.com> | 2025-03-21 17:25:58 +0800 |
---|---|---|
committer | Michael Tokarev <mjt@tls.msk.ru> | 2025-03-24 23:49:58 +0300 |
commit | a2d22778addb41facaa7553386c4c39dc4c47499 (patch) | |
tree | 0dc7c899eab5dd19f3c9123b1e8ab965cc820db8 | |
parent | d63f951f4746f080fbdc11e577f1fba931be8cdc (diff) | |
download | qemu-a2d22778addb41facaa7553386c4c39dc4c47499.zip qemu-a2d22778addb41facaa7553386c4c39dc4c47499.tar.gz qemu-a2d22778addb41facaa7553386c4c39dc4c47499.tar.bz2 |
hw/misc/aspeed_hace: Fix buffer overflow in has_padding function
The maximum padding size is either 64 or 128 bytes and should always be smaller
than "req_len". If "padding_size" exceeds "req_len", then
"req_len - padding_size" underflows due to "uint32_t" data type, leading to a
large incorrect value (e.g., `0xFFXXXXXX`). This causes an out-of-bounds memory
access, potentially leading to a buffer overflow.
Added a check to ensure "padding_size" does not exceed "req_len" before
computing "pad_offset". This prevents "req_len - padding_size" from underflowing
and avoids accessing invalid memory.
Signed-off-by: Jamin Lin <jamin_lin@aspeedtech.com>
Reviewed-by: Cédric Le Goater <clg@redhat.com>
Fixes: 5cd7d8564a8b563da724b9e6264c967f0a091afa ("aspeed/hace: Support AST2600 HACE ")
Link: https://lore.kernel.org/qemu-devel/20250321092623.2097234-3-jamin_lin@aspeedtech.com
Signed-off-by: Cédric Le Goater <clg@redhat.com>
(cherry picked from commit 78877b2e06464f49f777e086845e094ea7bc82ef)
Signed-off-by: Michael Tokarev <mjt@tls.msk.ru>
-rw-r--r-- | hw/misc/aspeed_hace.c | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/hw/misc/aspeed_hace.c b/hw/misc/aspeed_hace.c index b07506e..8706e3d 100644 --- a/hw/misc/aspeed_hace.c +++ b/hw/misc/aspeed_hace.c @@ -123,6 +123,11 @@ static bool has_padding(AspeedHACEState *s, struct iovec *iov, if (*total_msg_len <= s->total_req_len) { uint32_t padding_size = s->total_req_len - *total_msg_len; uint8_t *padding = iov->iov_base; + + if (padding_size > req_len) { + return false; + } + *pad_offset = req_len - padding_size; if (padding[*pad_offset] == 0x80) { return true; |