From patchwork Tue Jun 10 07:42:47 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Lieven X-Patchwork-Id: 357762 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 46DCE1400AF for ; Tue, 10 Jun 2014 17:44:13 +1000 (EST) Received: from localhost ([::1]:37265 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuGj5-0000d2-8V for incoming@patchwork.ozlabs.org; Tue, 10 Jun 2014 03:44:11 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45446) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuGik-0000Ku-Lv for qemu-devel@nongnu.org; Tue, 10 Jun 2014 03:43:56 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1WuGie-00008J-T9 for qemu-devel@nongnu.org; Tue, 10 Jun 2014 03:43:50 -0400 Received: from mx-v6.kamp.de ([2a02:248:0:51::16]:47826 helo=mx01.kamp.de) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1WuGie-00007a-Jb for qemu-devel@nongnu.org; Tue, 10 Jun 2014 03:43:44 -0400 Received: (qmail 32596 invoked by uid 89); 10 Jun 2014 07:43:42 -0000 Received: from [82.141.1.145] by client-16-kamp (envelope-from , uid 89) with qmail-scanner-2010/03/19-MF (clamdscan: 0.98.3/19080. hbedv: 8.3.20.8/7.11.154.26. spamassassin: 3.4.0. Clear:RC:1(82.141.1.145):SA:0(-1.2/4.0):. Processed in 1.09306 secs); 10 Jun 2014 07:43:42 -0000 Received: from ns.kamp-intra.net (HELO dns.kamp-intra.net) ([82.141.1.145]) by mx01.kamp.de with SMTP; 10 Jun 2014 07:43:40 -0000 X-GL_Whitelist: yes Received: from lieven-pc.kamp-intra.net (lieven-pc.kamp-intra.net [172.21.12.60]) by dns.kamp-intra.net (Postfix) with ESMTP id C499920695; Tue, 10 Jun 2014 09:43:10 +0200 (CEST) Received: by lieven-pc.kamp-intra.net (Postfix, from userid 1000) id B3D795FC70; Tue, 10 Jun 2014 09:43:10 +0200 (CEST) From: Peter Lieven To: qemu-devel@nongnu.org Date: Tue, 10 Jun 2014 09:42:47 +0200 Message-Id: <1402386167-8091-1-git-send-email-pl@kamp.de> X-Mailer: git-send-email 1.7.9.5 X-detected-operating-system: by eggs.gnu.org: Error: Malformed IPv6 address (bad octet value). X-Received-From: 2a02:248:0:51::16 Cc: kwolf@redhat.com, pbonzini@redhat.com, Peter Lieven , stefanha@redhat.com Subject: [Qemu-devel] [PATCH] block/nfs: 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 it will happen in the future that the callback of a libnfs call directly invokes the callback. In this case we end up in a segfault because the NFSRPC is gone when we the BH is scheduled. Signed-off-by: Peter Lieven --- block/nfs.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/block/nfs.c b/block/nfs.c index bd9177f..e282f8d 100644 --- a/block/nfs.c +++ b/block/nfs.c @@ -95,6 +95,7 @@ static void nfs_co_init_task(NFSClient *client, NFSRPC *task) static void nfs_co_generic_bh_cb(void *opaque) { NFSRPC *task = opaque; + task->complete = 1; qemu_bh_delete(task->bh); qemu_coroutine_enter(task->co, NULL); } @@ -104,7 +105,6 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, void *private_data) { NFSRPC *task = private_data; - task->complete = 1; task->ret = ret; if (task->ret > 0 && task->iov) { if (task->ret <= task->iov->size) { @@ -123,6 +123,8 @@ nfs_co_generic_cb(int ret, struct nfs_context *nfs, void *data, task->bh = aio_bh_new(task->client->aio_context, nfs_co_generic_bh_cb, task); qemu_bh_schedule(task->bh); + } else { + task->complete = 1; } }