From: Paolo Bonzini <pbonzini@redhat.com>
To: Stefan Hajnoczi <stefanha@redhat.com>, qemu-devel@nongnu.org
Cc: Ronnie Sahlberg <ronniesahlberg@gmail.com>,
qemu-block@nongnu.org, Peter Lieven <pl@kamp.de>,
Felipe Franciosi <felipe@nutanix.com>
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2 3/3] block/iscsi: fix ioctl cancel use-after-free
Date: Fri, 9 Feb 2018 18:48:19 +0100 [thread overview]
Message-ID: <5c84595b-dc38-aa6c-5bda-e16f70fc68be@redhat.com> (raw)
In-Reply-To: <20180203061621.7033-4-stefanha@redhat.com>
On 03/02/2018 07:16, Stefan Hajnoczi wrote:
> @@ -298,14 +301,25 @@ iscsi_aio_cancel(BlockAIOCB *blockacb)
> IscsiAIOCB *acb = (IscsiAIOCB *)blockacb;
> IscsiLun *iscsilun = acb->iscsilun;
>
> - if (acb->status != -EINPROGRESS) {
> + qemu_mutex_lock(&iscsilun->mutex);
> +
> + /* If it was cancelled or completed already, our work is done here */
> + if (acb->cancelled || acb->status != -EINPROGRESS) {
> + qemu_mutex_unlock(&iscsilun->mutex);
> return;
> }
>
> + acb->cancelled = true;
> +
> + qemu_aio_ref(acb); /* released in iscsi_abort_task_cb() */
qemu_aio_ref is not thread safe. I think this is fine however, since
all qemu_aio_ref/unref calls should happen in the I/O thread.
Regarding your follow-up patch:
>
> - acb->status = -ECANCELED;
> - iscsi_schedule_bh(acb);
> + /* If the command callback hasn't been called yet, drop the task */
> + if (!acb->bh) {
> + /* Call iscsi_aio_ioctl_cb() with SCSI_STATUS_CANCELLED */
> + iscsi_scsi_cancel_task(iscsi, acb->task);
> + }
> +
SCSI_STATUS_CANCELLED is a libiscsi addition and should not go past
iscsi_aio_ioctl_cb. So you'd need something like this:
diff --git a/block/iscsi.c b/block/iscsi.c
index 6a1c53711a..ace6ca900f 100644
--- a/block/iscsi.c
+++ b/block/iscsi.c
@@ -928,6 +928,14 @@ iscsi_aio_ioctl_cb(struct iscsi_context *iscsi,
g_free(acb->buf);
acb->buf = NULL;
+ if (status == SCSI_STATUS_CANCELLED) {
+ if (!acb->bh) {
+ acb->status = -ECANCELED);
+ iscsi_schedule_bh(acb);
+ }
+ return;
+ }
+
acb->status = 0;
if (status < 0) {
error_report("Failed to ioctl(SG_IO) to iSCSI lun. %s",
Needless to say, it is really unfortunate that there is no mock iSCSI
server to write tests for. :(
Paolo
next prev parent reply other threads:[~2018-02-09 17:48 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-02-03 6:16 [Qemu-devel] [PATCH v2 0/3] block/iscsi: fix ioctl cancel use-after-free Stefan Hajnoczi
2018-02-03 6:16 ` [Qemu-devel] [PATCH v2 1/3] block/iscsi: drop unused IscsiAIOCB->buf field Stefan Hajnoczi
2018-02-09 17:48 ` Paolo Bonzini
2018-02-03 6:16 ` [Qemu-devel] [PATCH v2 2/3] block/iscsi: take iscsilun->mutex in iscsi_timed_check_events() Stefan Hajnoczi
2018-02-09 17:49 ` Paolo Bonzini
2018-02-03 6:16 ` [Qemu-devel] [PATCH v2 3/3] block/iscsi: fix ioctl cancel use-after-free Stefan Hajnoczi
2018-02-09 17:48 ` Paolo Bonzini [this message]
2018-02-09 17:50 ` Paolo Bonzini
2018-02-13 16:52 ` Stefan Hajnoczi
2018-02-14 16:08 ` Felipe Franciosi
2018-02-15 10:37 ` [Qemu-devel] [PATCH v2 0/3] " Stefan Hajnoczi
2018-11-29 9:23 ` Paolo Bonzini
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=5c84595b-dc38-aa6c-5bda-e16f70fc68be@redhat.com \
--to=pbonzini@redhat.com \
--cc=felipe@nutanix.com \
--cc=pl@kamp.de \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=ronniesahlberg@gmail.com \
--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).