qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] hw/sd/sdcard: fix potential out-of-bounds read in rpmb_calc_hmac
@ 2025-11-06  7:28 zhaoguohan_salmon
  2025-11-14 13:39 ` Peter Maydell
  0 siblings, 1 reply; 8+ messages in thread
From: zhaoguohan_salmon @ 2025-11-06  7:28 UTC (permalink / raw)
  To: philmd, bmeng.cn; +Cc: qemu-block, qemu-devel, GuoHan Zhao

From: GuoHan Zhao <zhaoguohan@kylinos.cn>

Coverity reported a potential out-of-bounds read in rpmb_calc_hmac():

CID 1642869: Out-of-bounds read (OVERRUN)
Overrunning array of 256 bytes at byte offset 256 by dereferencing
pointer &frame->data[256].

The issue arises from using &frame->data[RPMB_DATA_LEN] as the source
pointer for memcpy(). Although computing a one-past-the-end pointer is
legal, dereferencing it (as memcpy() does) is undefined behavior in C.

Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
 hw/sd/sd.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/hw/sd/sd.c b/hw/sd/sd.c
index 9c86c016cc9d..bc2e9863a534 100644
--- a/hw/sd/sd.c
+++ b/hw/sd/sd.c
@@ -1161,7 +1161,8 @@ static bool rpmb_calc_hmac(SDState *sd, const RPMBDataFrame *frame,
 
         assert(RPMB_HASH_LEN <= sizeof(sd->data));
 
-        memcpy((uint8_t *)buf + RPMB_DATA_LEN, &frame->data[RPMB_DATA_LEN],
+        memcpy((uint8_t *)buf + RPMB_DATA_LEN,
+               (const uint8_t *)frame + RPMB_DATA_LEN,
                RPMB_HASH_LEN - RPMB_DATA_LEN);
         offset = lduw_be_p(&frame->address) * RPMB_DATA_LEN + sd_part_offset(sd);
         do {
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2025-11-14 20:45 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-06  7:28 [PATCH] hw/sd/sdcard: fix potential out-of-bounds read in rpmb_calc_hmac zhaoguohan_salmon
2025-11-14 13:39 ` Peter Maydell
2025-11-14 20:10   ` Jan Kiszka
2025-11-14 20:26   ` Philippe Mathieu-Daudé
2025-11-14 20:27     ` Jan Kiszka
2025-11-14 20:34       ` Philippe Mathieu-Daudé
2025-11-14 20:42         ` Jan Kiszka
2025-11-14 20:44           ` Philippe Mathieu-Daudé

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).