Skip to content

Commit 193ff95

Browse files
ZheyuMaPatchew Applier
authored and
Patchew Applier
committed
hw/display/tcx: Fix out-of-bounds access in tcx_blit_writel
This patch addresses a potential out-of-bounds memory access issue in the tcx_blit_writel function. It adds bounds checking to ensure that memory accesses do not exceed the allocated VRAM size. If an out-of-bounds access is detected, an error is logged using qemu_log_mask. ASAN log: ==2960379==ERROR: AddressSanitizer: SEGV on unknown address 0x7f524752fd01 (pc 0x7f525c2c4881 bp 0x7ffdaf87bfd0 sp 0x7ffdaf87b788 T0) ==2960379==The signal is caused by a READ memory access. #0 0x7f525c2c4881 in memcpy string/../sysdeps/x86_64/multiarch/memmove-vec-unaligned-erms.S:222 #1 0x55aa782bd5b1 in __asan_memcpy llvm/compiler-rt/lib/asan/asan_interceptors_memintrinsics.cpp:22:3 #2 0x55aa7854dedd in tcx_blit_writel hw/display/tcx.c:590:13 Reproducer: cat << EOF | qemu-system-sparc -display none \ -machine accel=qtest, -m 512M -machine LX -m 256 -qtest stdio writel 0x562e98c4 0x3d92fd01 EOF Signed-off-by: Zheyu Ma <zheyuma97@gmail.com> Message-Id: <20240630130426.2966539-1-zheyuma97@gmail.com>
1 parent 3665dd6 commit 193ff95

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

hw/display/tcx.c

+9
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
#include "migration/vmstate.h"
3434
#include "qemu/error-report.h"
3535
#include "qemu/module.h"
36+
#include "qemu/log.h"
3637
#include "qom/object.h"
3738

3839
#define TCX_ROM_FILE "QEMU,tcx.bin"
@@ -577,6 +578,14 @@ static void tcx_blit_writel(void *opaque, hwaddr addr,
577578
addr = (addr >> 3) & 0xfffff;
578579
adsr = val & 0xffffff;
579580
len = ((val >> 24) & 0x1f) + 1;
581+
582+
if (addr + len > s->vram_size || adsr + len > s->vram_size) {
583+
qemu_log_mask(LOG_GUEST_ERROR,
584+
"%s: VRAM access out of bounds. addr: 0x%lx, adsr: 0x%x, len: %u\n",
585+
__func__, addr, adsr, len);
586+
return;
587+
}
588+
580589
if (adsr == 0xffffff) {
581590
memset(&s->vram[addr], s->tmpblit, len);
582591
if (s->depth == 24) {

0 commit comments

Comments
 (0)