system/physmem: Silence warning from ubsan
PATCH 1/1 system/physmem: Silence warning from ubsan
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when running the bios-tables-test for example:
.../system/physmem.c:3243:13: runtime error: applying non-zero offset 262144 to null pointer
#0 0x55ac1df5fbc4 in address_space_write_rom_internal .../system/physmem.c:3243:13
The problem is that buf is indeed NULL if the function is e.g. called with type == FLUSH_CACHE. Add a check to fix the issue.
--- system/physmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)
system/physmem.c +3 -1
@@ -3240,8 +3240,10 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as, } } len -= l; - buf += l; addr += l; +if (buf) { + buf += l; + } }return MEMTX_OK ; }
Signature · 1 line
2.50.1
Cc'ing Patrick & Peter for similar patch:
https://lore.kernel.org/qemu-devel/[email protected]/
Quoted 32 lines · Thomas Huth
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when running the bios-tables-test for example:
.../system/physmem.c:3243:13: runtime error: applying non-zero offset 262144 to null pointer#0 0x55ac1df5fbc4 in address_space_write_rom_internal .../system/physmem.c:3243:13The problem is that buf is indeed NULL if the function is e.g. called with type ==
FLUSH_CACHE. Add a check to fix the issue.Signed-off-by Thomas Huth <[email protected]>--- system/physmem.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-)system/physmem.c +3
-1@@ -3240,8 +3240,10 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as, } } len -= l; - buf += l; addr += l; +if (buf) { + buf += l; + } }return MEMTX_OK ; }
Quoted 2 lines · Philippe Mathieu-Daudé
Cc'ing Patrick & Peter for similar patch:
https://lore.kernel.org/qemu-devel/[email protected]/
This version seems to work.
Quoted 9 lines · Thomas Huth
Quoted 7 lines
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when running the bios-tables-test for example:
.../system/physmem.c:3243:13: runtime error: applying non-zero offset 262144 to null pointer#0 0x55ac1df5fbc4 in address_space_write_rom_internal .../system/physmem.c:3243:13
I can trigger this by as simple as "./qemu-system-x86_64 -accel kvm". I queued it, thanks.
Signature · 1 line
Peter Xu
Quoted 5 lines · Thomas Huth
From: Thomas Huth <[email protected]>
When compiling QEMU with --enable-ubsan there is a undefined behavior warning when running the bios-tables-test for example:
Quoted 7 lines
.../system/physmem.c:3243:13: runtime error: applying non-zero offset 262144 to null pointer#0 0x55ac1df5fbc4 in address_space_write_rom_internal .../system/physmem.c:3243:13The problem is that buf is indeed NULL if the function is e.g. called with type ==
FLUSH_CACHE. Add a check to fix the issue.Signed-off-by Thomas Huth <[email protected]>
Signature · 3 lines
Cheers, David / dhildenb