All of lore.kernel.org
 help / color / mirror / Atom feed
From: Greg Kurz <groug@kaod.org>
To: qemu-devel@nongnu.org
Cc: qemu-ppc@nongnu.org, "David Gibson" <david@gibson.dropbear.id.au>,
	"Cédric Le Goater" <clg@kaod.org>
Subject: [Qemu-devel] [PATCH 2/5] spapr_cpu_core: fix potential leak in spapr_cpu_core_realize()
Date: Thu, 14 Jun 2018 23:50:27 +0200	[thread overview]
Message-ID: <152901302718.252222.18367624313137740494.stgit@bahia.lan> (raw)
In-Reply-To: <152901299450.252222.14219708016930421485.stgit@bahia.lan>

Commit 94ad93bd97684 (QEMU 2.12) switched to instantiate CPUs separately
but it missed to adapt the error path accordingly. If something fails in
the CPU creation loop, then the CPU object that was just created is leaked.

The error paths in this function are a bit obfuscated, and adding
yet another label to free this CPU object makes it worse. We should
move the block of the loop to a separate function, with a proper
rollback path, but this is a bigger cleanup.

For now, let's just fix the bug by adding the missing calls to
object_unref(). This will allow easier backport to older QEMU
versions.

Signed-off-by: Greg Kurz <groug@kaod.org>
---
 hw/ppc/spapr_cpu_core.c |    2 ++
 1 file changed, 2 insertions(+)

diff --git a/hw/ppc/spapr_cpu_core.c b/hw/ppc/spapr_cpu_core.c
index 27602245fd55..003c4c5a79d2 100644
--- a/hw/ppc/spapr_cpu_core.c
+++ b/hw/ppc/spapr_cpu_core.c
@@ -201,6 +201,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
         cs->cpu_index = cc->core_id + i;
         spapr_set_vcpu_id(cpu, cs->cpu_index, &local_err);
         if (local_err) {
+            object_unref(obj);
             goto err;
         }
 
@@ -212,6 +213,7 @@ static void spapr_cpu_core_realize(DeviceState *dev, Error **errp)
         object_property_add_child(OBJECT(sc), id, obj, &local_err);
         g_free(id);
         if (local_err) {
+            object_unref(obj);
             goto err;
         }
         object_unref(obj);

  parent reply	other threads:[~2018-06-14 21:50 UTC|newest]

Thread overview: 22+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-06-14 21:49 [Qemu-devel] [PATCH 0/5] spapr_cpu_core: fixes and cleanups Greg Kurz
2018-06-14 21:50 ` [Qemu-devel] [PATCH 1/5] spapr_cpu_core: convert last snprintf() to g_strdup_printf() Greg Kurz
2018-06-14 23:59   ` David Gibson
2018-06-14 21:50 ` Greg Kurz [this message]
2018-06-14 23:59   ` [Qemu-devel] [PATCH 2/5] spapr_cpu_core: fix potential leak in spapr_cpu_core_realize() David Gibson
2018-06-14 21:50 ` [Qemu-devel] [PATCH 3/5] spapr_cpu_core: add missing rollback on realization path Greg Kurz
2018-06-15  0:02   ` David Gibson
2018-06-15  0:14     ` David Gibson
2018-06-15  5:58       ` Greg Kurz
2018-06-15  6:29         ` David Gibson
2018-06-15  7:07           ` Greg Kurz
2018-06-15  8:01             ` Greg Kurz
2018-06-15 12:32               ` David Gibson
2018-06-15 13:24                 ` Greg Kurz
2018-06-16  6:26                   ` David Gibson
2018-06-15  5:53     ` Greg Kurz
2018-06-15  6:27       ` David Gibson
2018-06-14 21:50 ` [Qemu-devel] [PATCH 4/5] spapr_cpu_core: introduce spapr_create_vcpu() Greg Kurz
2018-06-15  0:05   ` David Gibson
2018-06-14 21:51 ` [Qemu-devel] [PATCH 5/5] spapr_cpu_core: simplify spapr_cpu_core_realize() Greg Kurz
2018-06-15  0:08   ` David Gibson
2018-06-15  6:57     ` Greg Kurz

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=152901302718.252222.18367624313137740494.stgit@bahia.lan \
    --to=groug@kaod.org \
    --cc=clg@kaod.org \
    --cc=david@gibson.dropbear.id.au \
    --cc=qemu-devel@nongnu.org \
    --cc=qemu-ppc@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 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.