From patchwork Wed Jun 18 16:03:56 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Bonzini X-Patchwork-Id: 361567 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id A19B4140086 for ; Thu, 19 Jun 2014 02:06:53 +1000 (EST) Received: from localhost ([::1]:58671 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxINv-0003Qh-Po for incoming@patchwork.ozlabs.org; Wed, 18 Jun 2014 12:06:51 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:56863) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxILf-0008Jk-Hk for qemu-devel@nongnu.org; Wed, 18 Jun 2014 12:04:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WxILZ-0008Fc-PT for qemu-devel@nongnu.org; Wed, 18 Jun 2014 12:04:31 -0400 Received: from mx1.redhat.com ([209.132.183.28]:53602) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WxILZ-0008Ew-I4 for qemu-devel@nongnu.org; Wed, 18 Jun 2014 12:04:25 -0400 Received: from int-mx09.intmail.prod.int.phx2.redhat.com (int-mx09.intmail.prod.int.phx2.redhat.com [10.5.11.22]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s5IG4Ia9024725 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 18 Jun 2014 12:04:18 -0400 Received: from playground.com (ovpn-112-50.ams2.redhat.com [10.36.112.50]) by int-mx09.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s5IG4BSG019566; Wed, 18 Jun 2014 12:04:17 -0400 From: Paolo Bonzini To: qemu-devel@nongnu.org Date: Wed, 18 Jun 2014 18:03:56 +0200 Message-Id: <1403107449-6186-3-git-send-email-pbonzini@redhat.com> In-Reply-To: <1403107449-6186-1-git-send-email-pbonzini@redhat.com> References: <1403107449-6186-1-git-send-email-pbonzini@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.22 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: Peter Lieven Subject: [Qemu-devel] [PULL 02/15] block/iscsi: fix potential segfault on early callback X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org From: Peter Lieven it might happen in the future that a function directly invokes its callback. In this case we end up in a segfault because the iTask is gone when the BH is scheduled. Signed-off-by: Peter Lieven Signed-off-by: Paolo Bonzini --- block/iscsi.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/block/iscsi.c b/block/iscsi.c index e64659f..09485fe 100644 --- a/block/iscsi.c +++ b/block/iscsi.c @@ -144,6 +144,7 @@ iscsi_schedule_bh(IscsiAIOCB *acb) static void iscsi_co_generic_bh_cb(void *opaque) { struct IscsiTask *iTask = opaque; + iTask->complete = 1; qemu_bh_delete(iTask->bh); qemu_coroutine_enter(iTask->co, NULL); } @@ -151,6 +152,7 @@ static void iscsi_co_generic_bh_cb(void *opaque) static void iscsi_retry_timer_expired(void *opaque) { struct IscsiTask *iTask = opaque; + iTask->complete = 1; if (iTask->co) { qemu_coroutine_enter(iTask->co, NULL); } @@ -168,7 +170,6 @@ iscsi_co_generic_cb(struct iscsi_context *iscsi, int status, struct IscsiTask *iTask = opaque; struct scsi_task *task = command_data; - iTask->complete = 1; iTask->status = status; iTask->do_retry = 0; iTask->task = task; @@ -205,6 +206,8 @@ out: iTask->bh = aio_bh_new(iTask->iscsilun->aio_context, iscsi_co_generic_bh_cb, iTask); qemu_bh_schedule(iTask->bh); + } else { + iTask->complete = 1; } }