From nobody Wed May 1 07:21:20 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 1528729100468994.7118008069236; Mon, 11 Jun 2018 07:58:20 -0700 (PDT) Received: from localhost ([::1]:49355 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSOGx-0003fU-MS for importer@patchew.org; Mon, 11 Jun 2018 10:58:19 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:33461) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1fSOFW-0002nj-VQ for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:56:51 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1fSOFW-0008Qv-29 for qemu-devel@nongnu.org; Mon, 11 Jun 2018 10:56:51 -0400 Received: from szxga02-in.huawei.com ([45.249.212.188]:2331 helo=huawei.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1fSOFR-0008Hi-8v; Mon, 11 Jun 2018 10:56:45 -0400 Received: from DGGEML403-HUB.china.huawei.com (unknown [172.30.72.57]) by Forcepoint Email with ESMTP id 94EDF854A097F; Mon, 11 Jun 2018 22:56:27 +0800 (CST) Received: from localhost.localdomain (10.175.104.211) by DGGEML403-HUB.china.huawei.com (10.3.17.33) with Microsoft SMTP Server id 14.3.382.0; Mon, 11 Jun 2018 22:56:21 +0800 From: Jie Wang To: , Date: Mon, 11 Jun 2018 20:42:02 +0800 Message-ID: <1528720922-20799-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.188 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 --- 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