Skip to contentSkip to conversation

hw/misc/aspeed_hace: Fix OOB read in has_padding()

PATCH In review Cédric Le Goater 2 participants 2 messages Sep 8 Arm/Aspeed machine support

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 hw/misc/aspeed_hace: Fix OOB read in has_padding()

When total_msg_len equals total_req_len, padding_size is 0, making pad_offset equal to req_len. The subsequent padding[pad_offset] read accesses one byte past the buffer. Return false early when padding_size is zero.

Fixes 5cd7d8564a8b ("aspeed/hace: Support AST2600 HACE")
---
 hw/misc/aspeed_hace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/aspeed_hace.c +1 -1
index 8de05a9d98b3..bf8af710335d 100644
@@ -225,7 +225,7 @@ static bool has_padding(AspeedHACEState *s, struct iovec *iov,
         uint32_t padding_size = s->total_req_len - *total_msg_len;
         uint8_t *padding = iov->iov_base;
 
-        if (padding_size > req_len) {
+        if (padding_size == 0 || padding_size > req_len) {
             return false;
         }
 
Signature · 1 line
2.55.0
Reviewed-by on v1 1/1
#1 lore raw
Quoted 28 lines

Subject: [PATCH] hw/misc/aspeed_hace: Fix OOB read in has_padding()

When total_msg_len equals total_req_len, padding_size is 0, making pad_offset equal to req_len. The subsequent padding[pad_offset] read accesses one byte past the buffer. Return false early when padding_size is zero.

Fixes 5cd7d8564a8b ("aspeed/hace: Support AST2600 HACE")
---
 hw/misc/aspeed_hace.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
hw/misc/aspeed_hace.c index renamed from hw/misc/aspeed_hace.c +0 -0

8de05a9d98b3..bf8af710335d 100644

hw/misc/aspeed_hace.c +1 -2
@@ -225,7 +225,7 @@ static bool has_padding(AspeedHACEState *s, struct
 iovec *iov,
         uint32_t padding_size = s->total_req_len - *total_msg_len;
         uint8_t *padding = iov->iov_base;
 
-        if (padding_size > req_len) {
+        if (padding_size == 0 || padding_size > req_len) {
             return false;
         }
 
--
Quoted 1 line

2.55.0

Thanks,
Jamin