From nobody Mon May 6 13:49:36 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) client-ip=208.118.235.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; spf=pass (zoho.com: domain of gnu.org designates 208.118.235.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) by mx.zohomail.com with SMTPS id 152876784382618.34649030374669; Mon, 11 Jun 2018 18:44:03 -0700 (PDT) Received: from localhost ([::1]:52192 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSYLn-0001Yl-Ln for importer@patchew.org; Mon, 11 Jun 2018 21:43:59 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:39564) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSYKm-000178-Eq for qemu-devel@nongnu.org; Mon, 11 Jun 2018 21:42:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSYKl-000096-IH for qemu-devel@nongnu.org; Mon, 11 Jun 2018 21:42:56 -0400 Received: from [45.249.212.255] (port=60379 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSYKf-00005J-Bw; Mon, 11 Jun 2018 21:42:49 -0400 Received: from dggeml405-hub.china.huawei.com (unknown [172.30.72.53]) by Forcepoint Email with ESMTP id 9D0D41A33FA1F; Tue, 12 Jun 2018 09:42:44 +0800 (CST) Received: from localhost.localdomain (10.175.104.211) by dggeml405-hub.china.huawei.com (10.3.17.49) with Microsoft SMTP Server id 14.3.382.0; Tue, 12 Jun 2018 09:40:45 +0800 From: Jie Wang To: , Date: Tue, 12 Jun 2018 07:26:25 +0800 Message-ID: <1528759585-51780-1-git-send-email-wangjie88@huawei.com> X-Mailer: git-send-email 1.8.3.1 MIME-Version: 1.0 X-Originating-IP: [10.175.104.211] X-CFilter-Loop: Reflected X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 45.249.212.255 Subject: [Qemu-devel] [PATCH v2] util/async: avoid NULL pointer dereference X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: famz@redhat.com, eric.fangyi@huawei.com, stefanha@redhat.com, wangjie88@huawei.com, wu.wubin@huawei.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail: RSF_0 Z_629925259 SPT_0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" if laio_init create linux_aio failed and return NULL, NULL pointer dereference will occur when laio_attach_aio_context dereference linux_aio in aio_get_linux_aio. Let's avoid it and report error. Signed-off-by: Jie Wang Reviewed-by: Jeff Cody --- block/file-posix.c | 19 +++++++++++++++++-- util/async.c | 5 ++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/block/file-posix.c b/block/file-posix.c index 513d371bb1..653017d7a5 100644 --- a/block/file-posix.c +++ b/block/file-posix.c @@ -1665,6 +1665,11 @@ static int coroutine_fn raw_co_prw(BlockDriverState = *bs, uint64_t offset, #ifdef CONFIG_LINUX_AIO } else if (s->use_linux_aio) { LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(= bs)); + if (!aio) { + s->use_linux_aio =3D false; + error_report("Failed to get linux aio"); + return -EIO; + } assert(qiov->size =3D=3D bytes); return laio_co_submit(bs, aio, s->fd, offset, qiov, type); #endif @@ -1695,7 +1700,12 @@ static void raw_aio_plug(BlockDriverState *bs) BDRVRawState *s =3D bs->opaque; if (s->use_linux_aio) { LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); - laio_io_plug(bs, aio); + if (aio) { + laio_io_plug(bs, aio); + } else { + s->use_linux_aio =3D false; + error_report("Failed to get linux aio"); + } } #endif } @@ -1706,7 +1716,12 @@ static void raw_aio_unplug(BlockDriverState *bs) BDRVRawState *s =3D bs->opaque; if (s->use_linux_aio) { LinuxAioState *aio =3D aio_get_linux_aio(bdrv_get_aio_context(bs)); - laio_io_unplug(bs, aio); + if (aio) { + laio_io_unplug(bs, aio); + } else { + s->use_linux_aio =3D false; + error_report("Failed to get linux aio"); + } } #endif } diff --git a/util/async.c b/util/async.c index 03f62787f2..08d71340f8 100644 --- a/util/async.c +++ b/util/async.c @@ -327,8 +327,11 @@ LinuxAioState *aio_get_linux_aio(AioContext *ctx) { if (!ctx->linux_aio) { ctx->linux_aio =3D laio_init(); - laio_attach_aio_context(ctx->linux_aio, ctx); + if (ctx->linux_aio) { + laio_attach_aio_context(ctx->linux_aio, ctx); + } } + return ctx->linux_aio; } #endif --=20 2.15.0.windows.1