qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Michael Roth <mdroth@linux.vnet.ibm.com>
To: Paolo Bonzini <pbonzini@redhat.com>, qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 3/3] memory: keep the owner of the AddressSpace alive until do_address_space_destroy
Date: Wed, 11 Feb 2015 14:33:00 -0600	[thread overview]
Message-ID: <20150211203300.3809.937@loki> (raw)
In-Reply-To: <1423674872-10676-4-git-send-email-pbonzini@redhat.com>

Quoting Paolo Bonzini (2015-02-11 11:14:32)
> This fixes a use-after-free if do_address_space_destroy is executed
> too late.
> 
> Signed-off-by: Paolo Bonzini <pbonzini@redhat.com>

Looks like this did the trick for me. Haven't been able to reproduce for
a couple hours. Thanks!

Reviewed-by: Michael Roth <mdroth@linux.vnet.ibm.com>
Tested-by: Michael Roth <mdroth@linux.vnet.ibm.com>

> ---
>  memory.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/memory.c b/memory.c
> index 130152c..20f6d9e 100644
> --- a/memory.c
> +++ b/memory.c
> @@ -1943,6 +1943,7 @@ void memory_listener_unregister(MemoryListener *listener)
> 
>  void address_space_init(AddressSpace *as, MemoryRegion *root, const char *name)
>  {
> +    memory_region_ref(root);
>      memory_region_transaction_begin();
>      as->root = root;
>      as->current_map = g_new(FlatView, 1);
> @@ -1969,10 +1970,13 @@ static void do_address_space_destroy(AddressSpace *as)
>      flatview_unref(as->current_map);
>      g_free(as->name);
>      g_free(as->ioeventfds);
> +    memory_region_unref(as->root);
>  }
> 
>  void address_space_destroy(AddressSpace *as)
>  {
> +    MemoryRegion *root = as->root;
> +
>      /* Flush out anything from MemoryListeners listening in on this */
>      memory_region_transaction_begin();
>      as->root = NULL;
> @@ -1984,6 +1988,7 @@ void address_space_destroy(AddressSpace *as)
>       * entries that the guest should never use.  Wait for the old
>       * values to expire before freeing the data.
>       */
> +    as->root = root;
>      call_rcu(as, do_address_space_destroy, rcu);
>  }
> 
> -- 
> 1.8.3.1

      reply	other threads:[~2015-02-11 20:33 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-11 17:14 [Qemu-devel] [PATCH 0/3] run RCU callbacks within the iothread mutex, fix PCI hotplug Paolo Bonzini
2015-02-11 17:14 ` [Qemu-devel] [PATCH 1/3] rcu: do not let RCU callbacks pile up indefinitely Paolo Bonzini
2015-02-11 17:30   ` Paolo Bonzini
2015-02-12  9:05   ` Fam Zheng
2015-02-11 17:14 ` [Qemu-devel] [PATCH 2/3] rcu: run RCU callbacks under the BQL Paolo Bonzini
2015-02-11 20:26   ` Michael Roth
2015-02-11 20:39     ` Paolo Bonzini
2015-02-11 17:14 ` [Qemu-devel] [PATCH 3/3] memory: keep the owner of the AddressSpace alive until do_address_space_destroy Paolo Bonzini
2015-02-11 20:33   ` Michael Roth [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=20150211203300.3809.937@loki \
    --to=mdroth@linux.vnet.ibm.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    /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).