qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Max Reitz <mreitz@redhat.com>
To: Peter Maydell <peter.maydell@linaro.org>,
	QEMU Developers <qemu-devel@nongnu.org>,
	Qemu-block <qemu-block@nongnu.org>
Subject: Re: [Qemu-devel] [Qemu-block] could somebody who understands the block refcounting look at CID 1395870, CID 1395871?
Date: Mon, 29 Oct 2018 17:35:09 +0100	[thread overview]
Message-ID: <c4bf0aa6-f53e-7197-e2d4-c3a553af378c@redhat.com> (raw)
In-Reply-To: <CAFEAcA8R6dPxEq=-6oZiHSzgkaMWfjyKvXip6FG4h5HWj4mtwQ@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1573 bytes --]

On 29.10.18 11:51, Peter Maydell wrote:
> Hi; could somebody who understands the block layer refcounting have
> a look at Coverity issues CID 1395870 and 1395871, please?

Don't forget 1395869.

> In both
> cases, Coverity reports a use-after-free because it thinks that a
> sequence where a code path might (conditionally) end up calling
> blk_deref() twice could be freeing the memory in the first call
> and using it after. I'm not sure whether these are false positives
> because the refcounting has confused Coverity, or genuine issues where
> we have got refcounting logic wrong, so I don't know if we need a
> fix or if we should squash the coverity bug as a false-positive...

It looks basically reasonable to me (just like 1395869).  All of these
block devices have two refcounts, one from the device state, and one
from the monitor.  These three places drop both refcounts after one another.

On first glance I found the order in qdev-properties-system.c a bit
weird because it unrefs the monitor reference first (which is definitely
there), and the device state reference only afterwards (which piix.c
implies may or may not be there).  However, @dev cannot be NULL
(otherwise "*ptr" would have segfaulted), so the device state reference
is guaranteed to be there.  OTOH, it appears that in this case the
monitor reference may be missing, so it's correct to try to drop that
reference first here, in case there is none.

So all looks good to me, I'll mark them as false positives (like Paolo
has done for 1395869 already).

Max


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

      reply	other threads:[~2018-10-29 16:35 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-10-29 10:51 [Qemu-devel] could somebody who understands the block refcounting look at CID 1395870, CID 1395871? Peter Maydell
2018-10-29 16:35 ` Max Reitz [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=c4bf0aa6-f53e-7197-e2d4-c3a553af378c@redhat.com \
    --to=mreitz@redhat.com \
    --cc=peter.maydell@linaro.org \
    --cc=qemu-block@nongnu.org \
    --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).