From: Jeff Cody <jcody@redhat.com>
To: Jie Wang <wangjie88@huawei.com>
Cc: qemu-devel@nongnu.org, qemu-block@nongnu.org, famz@redhat.com,
eric.fangyi@huawei.com, stefanha@redhat.com, wu.wubin@huawei.com
Subject: Re: [Qemu-devel] [Qemu-block] [PATCH v2] util/async: avoid NULL pointer dereference
Date: Mon, 11 Jun 2018 23:32:13 -0400 [thread overview]
Message-ID: <20180612033213.GA21017@localhost.localdomain> (raw)
In-Reply-To: <1528759585-51780-1-git-send-email-wangjie88@huawei.com>
On Tue, Jun 12, 2018 at 07:26:25AM +0800, Jie Wang wrote:
> 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 <wangjie88@huawei.com>
Reviewed-by: Jeff Cody <jcody@redhat.com>
> ---
> 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 = aio_get_linux_aio(bdrv_get_aio_context(bs));
> + if (!aio) {
> + s->use_linux_aio = false;
> + error_report("Failed to get linux aio");
> + return -EIO;
> + }
> assert(qiov->size == 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 = bs->opaque;
> if (s->use_linux_aio) {
> LinuxAioState *aio = 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 = false;
> + error_report("Failed to get linux aio");
> + }
> }
> #endif
> }
> @@ -1706,7 +1716,12 @@ static void raw_aio_unplug(BlockDriverState *bs)
> BDRVRawState *s = bs->opaque;
> if (s->use_linux_aio) {
> LinuxAioState *aio = 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 = 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 = 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
> --
> 2.15.0.windows.1
>
>
next prev parent reply other threads:[~2018-06-12 3:32 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2018-06-11 23:26 [Qemu-devel] [PATCH v2] util/async: avoid NULL pointer dereference Jie Wang
2018-06-12 3:32 ` Jeff Cody [this message]
2018-06-14 13:33 ` [Qemu-devel] ping Re: [Qemu-block] " WangJie (Pluto)
2018-06-18 15:50 ` [Qemu-devel] " Stefan Hajnoczi
2018-06-18 16:53 ` [Qemu-devel] [Qemu-block] " Kevin Wolf
2018-06-26 2:51 ` [Qemu-devel] " WangJie (Pluto)
2018-06-27 12:11 ` Stefan Hajnoczi
2018-06-19 2:15 ` [Qemu-devel] Ping? " WangJie (Pluto)
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=20180612033213.GA21017@localhost.localdomain \
--to=jcody@redhat.com \
--cc=eric.fangyi@huawei.com \
--cc=famz@redhat.com \
--cc=qemu-block@nongnu.org \
--cc=qemu-devel@nongnu.org \
--cc=stefanha@redhat.com \
--cc=wangjie88@huawei.com \
--cc=wu.wubin@huawei.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.