From: Peter Xu <peterx@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>
Cc: Joe Komlodi <komlodi@google.com>,
qemu-devel@nongnu.org, pbonzini@redhat.com, david@redhat.com,
philmd@linaro.org, venture@google.com, pefoley@google.com
Subject: Re: [PATCH] system/physmem: Fix UBSan finding in address_space_write_rom_internal
Date: Fri, 9 May 2025 11:22:10 -0400 [thread overview]
Message-ID: <aB4dohpeqnWlmurA@x1.local> (raw)
In-Reply-To: <CAFEAcA_65vRzAp1DzcZSDPWG+vX1C6xuh_2afdHqmXVFKZADmg@mail.gmail.com>
On Tue, May 06, 2025 at 02:21:08PM +0100, Peter Maydell wrote:
> On Mon, 5 May 2025 at 23:23, Joe Komlodi <komlodi@google.com> wrote:
> >
> > address_space_write_rom_internal can take in a NULL pointer for ptr if
> > it's only doing cache flushes instead of populating the ROM.
> >
> > However, if building with --enable-ubsan, incrementing buf causes ubsan
> > to go off when doing cache flushes, since it will trigger on pointer
> > arithmetic on a NULL pointer, even if that NULL pointer doesn't get
> > dereferenced.
> >
> > To fix this, we can move the buf incrementing to only be done when
> > writing data to ROM, since that's the only point where it gets
> > dereferenced and should be non-NULL.
> >
> > Found by running:
> > qemu-system-aarch64 \
> > -machine virt \
> > -accel kvm
> >
> > When built with --enable-ubsan.
> >
> > Signed-off-by: Joe Komlodi <komlodi@google.com>
> > ---
> > system/physmem.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/system/physmem.c b/system/physmem.c
> > index 16cf557d1a..ccd2b50da3 100644
> > --- a/system/physmem.c
> > +++ b/system/physmem.c
> > @@ -3204,6 +3204,7 @@ static inline MemTxResult address_space_write_rom_internal(AddressSpace *as,
> > case WRITE_DATA:
> > memcpy(ram_ptr, buf, l);
> > invalidate_and_set_dirty(mr, addr1, l);
> > + buf += l;
> > break;
>
> very minor, but I think the buf += l would be slightly better
> one line up, next to the memcpy(). That way we keep the
> "copy more data from buf" and "advance buf the corresponding
> amount" next to each other, rather than separating them by
> the set-dirty operation on the MR.
>
> Anyway
> Reviewed-by: Peter Maydell <peter.maydell@linaro.org>
I'll adjust that when sending a PR. Thanks!
--
Peter Xu
next prev parent reply other threads:[~2025-05-09 15:23 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2025-05-05 22:22 [PATCH] system/physmem: Fix UBSan finding in address_space_write_rom_internal Joe Komlodi
2025-05-06 13:16 ` Peter Xu
2025-05-06 13:21 ` Peter Maydell
2025-05-09 15:22 ` Peter Xu [this message]
2025-05-14 20:57 ` Peter Xu
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=aB4dohpeqnWlmurA@x1.local \
--to=peterx@redhat.com \
--cc=david@redhat.com \
--cc=komlodi@google.com \
--cc=pbonzini@redhat.com \
--cc=pefoley@google.com \
--cc=peter.maydell@linaro.org \
--cc=philmd@linaro.org \
--cc=qemu-devel@nongnu.org \
--cc=venture@google.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.