Skip to content

Commit 78877b2

Browse files
jamin-aspeedlegoater
authored andcommitted
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 <[email protected]> Reviewed-by: Cédric Le Goater <[email protected]> Fixes: 5cd7d85 ("aspeed/hace: Support AST2600 HACE ") Link: https://lore.kernel.org/qemu-devel/[email protected] Signed-off-by: Cédric Le Goater <[email protected]>
1 parent 7b8cbe5 commit 78877b2

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

hw/misc/aspeed_hace.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,11 @@ static bool has_padding(AspeedHACEState *s, struct iovec *iov,
128128
if (*total_msg_len <= s->total_req_len) {
129129
uint32_t padding_size = s->total_req_len - *total_msg_len;
130130
uint8_t *padding = iov->iov_base;
131+
132+
if (padding_size > req_len) {
133+
return false;
134+
}
135+
131136
*pad_offset = req_len - padding_size;
132137
if (padding[*pad_offset] == 0x80) {
133138
return true;

0 commit comments

Comments
 (0)