qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Eric Blake <eblake@redhat.com>
To: qemu-devel@nongnu.org
Cc: "Kevin Wolf" <kwolf@redhat.com>,
	"Peter Maydell" <peter.maydell@linaro.org>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	"Stefan Hajnoczi" <stefanha@redhat.com>
Subject: [PULL 02/10] qemu-coroutine-sleep: Silence Coverity warning
Date: Mon, 18 Nov 2019 21:07:51 -0600	[thread overview]
Message-ID: <20191119030759.24907-3-eblake@redhat.com> (raw)
In-Reply-To: <20191119030759.24907-1-eblake@redhat.com>

Coverity warns that we store the address of a stack variable through a
pointer passed in by the caller, which would let the caller trivially
trigger use-after-free if that stored value is still present when we
finish execution.  However, the way coroutines work is that after our
call to qemu_coroutine_yield(), control is temporarily continued in
the caller prior to our function concluding, and in order to resume
our coroutine, the caller must poll until the variable has been set to
NULL.  Thus, we can add an assert that we do not leak stack storage to
the caller on function exit.

Fixes: Coverity CID 1406474
CC: Peter Maydell <peter.maydell@linaro.org>
Signed-off-by: Eric Blake <eblake@redhat.com>
Message-Id: <20191111203524.21912-1-eblake@redhat.com>
Reviewed-by: Alex Bennée <alex.bennee@linaro.org>
---
 util/qemu-coroutine-sleep.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/util/qemu-coroutine-sleep.c b/util/qemu-coroutine-sleep.c
index ae91b92b6e78..769a76e57df0 100644
--- a/util/qemu-coroutine-sleep.c
+++ b/util/qemu-coroutine-sleep.c
@@ -68,5 +68,12 @@ void coroutine_fn qemu_co_sleep_ns_wakeable(QEMUClockType type, int64_t ns,
     }
     timer_mod(state.ts, qemu_clock_get_ns(type) + ns);
     qemu_coroutine_yield();
+    if (sleep_state) {
+        /*
+         * Note that *sleep_state is cleared during qemu_co_sleep_wake
+         * before resuming this coroutine.
+         */
+        assert(*sleep_state == NULL);
+    }
     timer_free(state.ts);
 }
-- 
2.21.0



  parent reply	other threads:[~2019-11-19  3:11 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-19  3:07 [PULL 00/10] NBD patches for 2019-11-19 for 4.2-rc2 Eric Blake
2019-11-19  3:07 ` [PULL 01/10] iotests: Test NBD client reconnection Eric Blake
2019-11-19  3:07 ` Eric Blake [this message]
2019-11-19  3:07 ` [PULL 03/10] nbd/server: Prefer heap over stack for parsing client names Eric Blake
2019-11-19  3:07 ` [PULL 04/10] bitmap: Enforce maximum bitmap name length Eric Blake
2019-11-19  3:07 ` [PULL 05/10] nbd: Don't send oversize strings Eric Blake
2019-11-19  3:07 ` [PULL 06/10] MAINTAINERS: add more bitmap-related to Dirty Bitmaps section Eric Blake
2019-11-19  3:07 ` [PULL 07/10] iotests: Fix 173 Eric Blake
2019-11-19  3:07 ` [PULL 08/10] iotests: Switch nbd tests to use Unix rather than TCP Eric Blake
2019-11-19  3:07 ` [PULL 09/10] iotests: Include QMP input in .out files Eric Blake
2019-11-19  3:07 ` [PULL 10/10] tests: More iotest 223 improvements Eric Blake
2019-11-19 11:28 ` [PULL 00/10] NBD patches for 2019-11-19 for 4.2-rc2 Peter Maydell

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=20191119030759.24907-3-eblake@redhat.com \
    --to=eblake@redhat.com \
    --cc=alex.bennee@linaro.org \
    --cc=kwolf@redhat.com \
    --cc=peter.maydell@linaro.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 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).