From: Dima Stepanov <dimastep@yandex-team.ru>
To: "Philippe Mathieu-Daudé" <f4bug@amsat.org>
Cc: qemu-devel@nongnu.org, pbonzini@redhat.com, wrfsh@yandex-team.ru
Subject: Re: [Qemu-devel] [PATCH v2 2/2] memory: fix possible NULL pointer dereference
Date: Wed, 11 Jul 2018 19:01:14 +0300 [thread overview]
Message-ID: <20180711160114.GA7198@dimastep-nix> (raw)
In-Reply-To: <69f9565f-e5f9-54f3-03dd-e610bea47ddc@amsat.org>
Hi Phil,
On Wed, Jul 11, 2018 at 10:47:18AM -0300, Philippe Mathieu-Daudé wrote:
> Hi Dima,
>
> On 07/11/2018 05:34 AM, Dima Stepanov wrote:
> > Gentle ping. CCing Paolo Bonzini.
> >
> > Regards, Dima.
> >
> > On Tue, Jun 19, 2018 at 05:12:16PM +0300, Dima Stepanov wrote:
> >> Ping.
> >>
> >> Regards, Dima.
> >>
> >> On Wed, Jun 13, 2018 at 11:19:55AM +0300, Dima Stepanov wrote:
> >>> In the memory_region_do_invalidate_mmio_ptr() routine the section
> >>> variable is intialized by the memory_region_find() call. The section.mr
> >>> field can be set to NULL.
> >>>
> >>> Add the check for NULL before trying to drop a section.
> >>>
> >>> Signed-off-by: Dima Stepanov <dimastep@yandex-team.ru>
> >>> ---
> >>> memory.c | 2 +-
> >>> 1 file changed, 1 insertion(+), 1 deletion(-)
> >>>
> >>> diff --git a/memory.c b/memory.c
> >>> index 3212acc..bb45248 100644
> >>> --- a/memory.c
> >>> +++ b/memory.c
> >>> @@ -2712,7 +2712,7 @@ static void memory_region_do_invalidate_mmio_ptr(CPUState *cpu,
> >>> /* Reset dirty so this doesn't happen later. */
> >>> cpu_physical_memory_test_and_clear_dirty(offset, size, 1);
> >>>
> >>> - if (section.mr != mr) {
> >>> + if (section.mr && (section.mr != mr)) {
>
> section.mr can't be NULL here.
>
> You can give the static analyzer a hint using "assert(section.mr);"
My point was:
section = memory_region_find(mr, offset, size) ->
ret = memory_region_find_rcu(mr, addr, size); ->
MemoryRegionSection ret = { .mr = NULL };
...
as = memory_region_to_address_space(root);
if this call returns NULL, then the ret value will be returned
(with .mr == NULL)
But maybe it is impossible for this case. Thanks for the reply.
Regards, Dima.
>
> >>> /* memory_region_find add a ref on section.mr */
> >>> memory_region_unref(section.mr);
> >>> if (MMIO_INTERFACE(section.mr->owner)) {
> >>> --
> >>> 2.7.4
> >>>
>
> Regards,
>
> Phil.
>
prev parent reply other threads:[~2018-07-11 16:01 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-13 8:19 [Qemu-devel] [PATCH v2 0/2] misc fixes found by static analyzer Dima Stepanov
2018-06-13 8:19 ` [Qemu-devel] [PATCH v2 1/2] memfd: fix possible usage of the uninitialized file descriptor Dima Stepanov
2018-06-13 10:00 ` Marc-André Lureau
2018-08-31 17:16 ` Thomas Huth
2018-06-13 8:19 ` [Qemu-devel] [PATCH v2 2/2] memory: fix possible NULL pointer dereference Dima Stepanov
2018-06-19 14:12 ` Dima Stepanov
2018-07-11 8:34 ` Dima Stepanov
2018-07-11 13:47 ` Philippe Mathieu-Daudé
2018-07-11 14:09 ` Peter Maydell
2018-07-11 16:03 ` Dima Stepanov
2018-07-11 16:01 ` Dima Stepanov [this message]
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=20180711160114.GA7198@dimastep-nix \
--to=dimastep@yandex-team.ru \
--cc=f4bug@amsat.org \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=wrfsh@yandex-team.ru \
/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 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).