* [PATCH] system/physmem: Silence warning from ubsan
@ 2025-07-28 17:25 Thomas Huth
  2025-07-28 18:43 ` Philippe Mathieu-Daudé
  2025-07-28 18:44 ` David Hildenbrand
  0 siblings, 2 replies; 4+ messages in thread
From: Thomas Huth @ 2025-07-28 17:25 UTC (permalink / raw)
  To: qemu-devel, Paolo Bonzini, Peter Xu, David Hildenbrand
  Cc: Philippe Mathieu-Daudé
From: Thomas Huth <thuth@redhat.com>
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.
Signed-off-by: Thomas Huth <thuth@redhat.com>
---
 system/physmem.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/system/physmem.c b/system/physmem.c
index 130c148ffb5..00333ffa7f7 100644
--- a/system/physmem.c
+++ b/system/physmem.c
@@ -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;
 }
-- 
2.50.1
^ permalink raw reply related	[flat|nested] 4+ messages in thread- * Re: [PATCH] system/physmem: Silence warning from ubsan
  2025-07-28 17:25 [PATCH] system/physmem: Silence warning from ubsan Thomas Huth
@ 2025-07-28 18:43 ` Philippe Mathieu-Daudé
  2025-07-29 19:21   ` Peter Xu
  2025-07-28 18:44 ` David Hildenbrand
  1 sibling, 1 reply; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2025-07-28 18:43 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Paolo Bonzini, Peter Xu,
	David Hildenbrand
  Cc: Patrick Venture, Peter Foley
Cc'ing Patrick & Peter for similar patch:
https://lore.kernel.org/qemu-devel/aCUDxEQVACn5CY8f@x1.local/
On 28/7/25 19:25, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> 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.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
> ---
>   system/physmem.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 
> diff --git a/system/physmem.c b/system/physmem.c
> index 130c148ffb5..00333ffa7f7 100644
> --- a/system/physmem.c
> +++ b/system/physmem.c
> @@ -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;
>   }
^ permalink raw reply	[flat|nested] 4+ messages in thread
- * Re: [PATCH] system/physmem: Silence warning from ubsan
  2025-07-28 18:43 ` Philippe Mathieu-Daudé
@ 2025-07-29 19:21   ` Peter Xu
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Xu @ 2025-07-29 19:21 UTC (permalink / raw)
  To: Philippe Mathieu-Daudé
  Cc: Thomas Huth, qemu-devel, Paolo Bonzini, David Hildenbrand,
	Patrick Venture, Peter Foley
On Mon, Jul 28, 2025 at 08:43:47PM +0200, Philippe Mathieu-Daudé wrote:
> Cc'ing Patrick & Peter for similar patch:
> https://lore.kernel.org/qemu-devel/aCUDxEQVACn5CY8f@x1.local/
This version seems to work.
> 
> On 28/7/25 19:25, Thomas Huth wrote:
> > From: Thomas Huth <thuth@redhat.com>
> > 
> > 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.
-- 
Peter Xu
^ permalink raw reply	[flat|nested] 4+ messages in thread 
 
- * Re: [PATCH] system/physmem: Silence warning from ubsan
  2025-07-28 17:25 [PATCH] system/physmem: Silence warning from ubsan Thomas Huth
  2025-07-28 18:43 ` Philippe Mathieu-Daudé
@ 2025-07-28 18:44 ` David Hildenbrand
  1 sibling, 0 replies; 4+ messages in thread
From: David Hildenbrand @ 2025-07-28 18:44 UTC (permalink / raw)
  To: Thomas Huth, qemu-devel, Paolo Bonzini, Peter Xu
  Cc: Philippe Mathieu-Daudé
On 28.07.25 19:25, Thomas Huth wrote:
> From: Thomas Huth <thuth@redhat.com>
> 
> 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.
> 
> Signed-off-by: Thomas Huth <thuth@redhat.com>
Reviewed-by: David Hildenbrand <david@redhat.com>
-- 
Cheers,
David / dhildenb
^ permalink raw reply	[flat|nested] 4+ messages in thread 
end of thread, other threads:[~2025-07-29 21:46 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-07-28 17:25 [PATCH] system/physmem: Silence warning from ubsan Thomas Huth
2025-07-28 18:43 ` Philippe Mathieu-Daudé
2025-07-29 19:21   ` Peter Xu
2025-07-28 18:44 ` David Hildenbrand
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).