All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Daniel P. Berrangé" <berrange@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>
Cc: Eric Blake <eblake@redhat.com>,
	qemu-devel@nongnu.org, Paolo Bonzini <pbonzini@redhat.com>,
	qemu-block@nongnu.org, Fam Zheng <fam@euphon.net>,
	Benjamin Marzinski <bmarzins@redhat.com>,
	kwolf@redhat.com
Subject: Re: [PATCH] qemu-pr-helper: do not free reply when multipath_process_cmd() fails
Date: Fri, 23 Oct 2026 10:53:18 +0100	[thread overview]
Message-ID: <atsujuqwo49tVwnC@redhat.com> (raw)
In-Reply-To: <20261019205710.GB159294@shajnocz.csb>

On Mon, Oct 19, 2026 at 04:57:10PM -0400, Stefan Hajnoczi wrote:
> On Mon, Oct 19, 2026 at 11:19:29AM -0500, Eric Blake wrote:
> > On Mon, Oct 19, 2026 at 11:33:53AM -0400, Stefan Hajnoczi wrote:
> > > Kevin Wolf pointed out that the multipath_process_cmd() documentation
> > > only defines the value of reply on success. Don't touch it when the
> > > function returns -1.
> > > 
> > > The libmpathcmd implementation as of c78cf64a9e8e does not set *reply to
> > > NULL when its internal mpath_send_cmd() call fails, so I think Kevin's
> > > interpretation is correct.
> > > 
> > > As it stands, there is no observable bug in the QEMU code though because
> > > reply is initialized to NULL before calling multipath_process_cmd().
> > > This patch is just a cleanup.
> > > 
> > > Cc: Benjamin Marzinski <bmarzins@redhat.com>
> > > Cc: kwolf@redhat.com
> > > Cc: eblake@redhat.com
> > > Signed-off-by: Stefan Hajnoczi <stefanha@redhat.com>
> > > ---
> > > Eric pointed out that g_autofree could eliminate the manual free(3)
> > > calls. In this case we cannot use it since g_autofree calls glib's
> > > g_free() rather than the standard library's free(3).
> > 
> > I know glib encourages g_free() in case malloc was interposed, but
> > aren't we guaranteed that we are not exploiting glib's malloc
> > overrides, and therefore g_free() calls into free(3)?  But I'm fine
> > with your decision to not use g_autofree here.
> 
> g_mem_set_vtable() is deprecated and a nop. Interposing no longer works.
> g_mem_is_system_malloc() always returns TRUE.
> 
> If we take advantage of glib internals, then you can call g_free() on
> malloc() memory AFAIK. But I don't think the API documentation
> guarantees this will always be the case and I'm not sure it's worth
> baking in this assumption.

Glib has public guaranteed this for years now, since I personally added
this guarantee to their API docs :-)

  "Since GLib 2.46, g_malloc() is hardcoded to always use the system
   malloc implementation."

   https://docs.gtk.org/glib/memory.html

QEMU has equally relied on this guarantee for years.

The only things we have to be wary of are other non-glib based 3rd
party libraries QEMU uses that may allow malloc overrides.

With regards,
Daniel
-- 
|: https://berrange.com       ~~        https://hachyderm.io/@berrange :|
|: https://libvirt.org          ~~          https://entangle-photo.org :|
|: https://pixelfed.art/berrange   ~~    https://fstop138.berrange.com :|



      reply	other threads:[~2026-10-23  9:54 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-19 15:33 [PATCH] qemu-pr-helper: do not free reply when multipath_process_cmd() fails Stefan Hajnoczi
2026-10-19 16:19 ` Eric Blake
2026-10-19 20:57   ` Stefan Hajnoczi
2026-10-23  9:53     ` Daniel P. Berrangé [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=atsujuqwo49tVwnC@redhat.com \
    --to=berrange@redhat.com \
    --cc=bmarzins@redhat.com \
    --cc=eblake@redhat.com \
    --cc=fam@euphon.net \
    --cc=kwolf@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=qemu-block@nongnu.org \
    --cc=qemu-devel@nongnu.org \
    --cc=stefanha@redhat.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.