curl: Don't deref NULL pointer in call to aio_poll.
PATCH v2 1/1 curl: Don't deref NULL pointer in call to aio_poll.
No change in the patch itself since v1. However I have added a longer explanation to the commit message.
Rich.
PATCH v2 1/1 curl: Don't deref NULL pointer in call to aio_poll.
In commit 63f0f45f2e89b60ff8245fec81328ddfde42a303 the following mechanical change was made:
if (!state) {
- qemu_aio_wait();
+ aio_poll(state->s->aio_context, true);
}The new code now checks if state is NULL and then dereferences it ('state->s') which is obviously incorrect.
This commit replaces state->s->aio_context with bdrv_get_aio_context(bs), fixing this problem. The two other hunks are concerned with getting the BlockDriverState pointer bs to where it is needed.
The original bug causes a segfault when using libguestfs to access a VMware vCenter Server and doing any kind of complex read-heavy operations. With this commit the segfault goes away.
--- block/curl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)
block/curl.c +4 -4
@@ -352,7 +352,7 @@ static void curl_multi_timeout_do(void *arg)#endif } -static CURLState *curl_init_state (BDRVCURLState *s) +static CURLState *curl_init_state (BlockDriverState *bs,BDRVCURLState *s) {CURLState *state =NULL ;int i, j;
@@ -370,7 +370,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)break ; }if (!state) { -aio_poll (state->s->aio_context, true); +aio_poll (bdrv_get_aio_context (bs), true); } }while (!state);
@@ -541,7 +541,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,DPRINTF ("CURL: Opening %s\n" , file); s->aio_context =bdrv_get_aio_context (bs); s->url =g_strdup (file); - state =curl_init_state (s); + state =curl_init_state (bs, s);if (!state) goto out_noclean;
@@ -625,7 +625,7 @@ static void curl_readv_bh_cb(void *p) }// No cache found, so let's start a new request - state =curl_init_state (s); + state =curl_init_state (acb->common.bs, s);if (!state) { acb->common.cb (acb->common.opaque, -EIO );qemu_aio_release (acb);
Signature · 1 line
2.0.4
Quoted 70 lines · Richard W.M. Jones
In commit
63f0f45f2e89b60ff8245fec81328ddfde42a303the following mechanical change was made:if (!state) {(quoted diff) +1
-1- qemu_aio_wait(); + aio_poll(state->s->aio_context, true); }The new code now checks if state is NULL and then dereferences it ('
state->s') which is obviously incorrect.This commit replaces
state->s->aio_contextwithbdrv_get_aio_context(bs), fixing this problem. The two other hunks are concerned with getting the BlockDriverState pointer bs to where it is needed.The original bug causes a segfault when using libguestfs to access a VMware vCenter Server and doing any kind of complex read-heavy operations. With this commit the segfault goes away.
Signed-off-by Richard W.M. Jones <[email protected]>Reviewed-by Paolo Bonzini <[email protected]>--- block/curl.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-)block/curl.c +4
-4@@ -352,7 +352,7 @@ static void curl_multi_timeout_do(void *arg)#endif } -static CURLState *curl_init_state (BDRVCURLState *s) +static CURLState *curl_init_state (BlockDriverState *bs,BDRVCURLState *s) {CURLState *state =NULL ;int i, j;@@ -370,7 +370,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)break ; }if (!state) { -aio_poll (state->s->aio_context, true); +aio_poll (bdrv_get_aio_context (bs), true); } }while (!state);@@ -541,7 +541,7 @@ static int curl_open(BlockDriverState *bs, QDict *options, int flags,DPRINTF ("CURL: Opening %s\n" , file); s->aio_context =bdrv_get_aio_context (bs); s->url =g_strdup (file); - state =curl_init_state (s); + state =curl_init_state (bs, s);if (!state) goto out_noclean;@@ -625,7 +625,7 @@ static void curl_readv_bh_cb(void *p) }// No cache found, so let's start a new request - state =curl_init_state (s); + state =curl_init_state (acb->common.bs, s);if (!state) { acb->common.cb (acb->common.opaque, -EIO );qemu_aio_release (acb);Signature · 1 line
2.0.4
block/curl.c static void curl_multi_timeout_do(void *arg) · line 358
Quoted 13 lines · Richard W.M. Jones
block/curl.c +1
-1@@ -352,7 +352,7 @@ static void curl_multi_timeout_do(void *arg)#endif } -static CURLState *curl_init_state (BDRVCURLState *s) +static CURLState *curl_init_state (BlockDriverState *bs,BDRVCURLState *s) {CURLState *state =NULL ;int i, j;
Why add the BDRVCURLState *s argument...
block/curl.c static CURLState *curl_init_state(BDRVCURLState *s) · line 376
Quoted 9 lines
block/curl.c +1
-1@@ -370,7 +370,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)break ; }if (!state) { -aio_poll (state->s->aio_context, true); +aio_poll (bdrv_get_aio_context (bs), true); } }while (!state);
...if it is not used?
Quoted 17 lines · Stefan Hajnoczi
block/curl.c static void curl_multi_timeout_do(void *arg) · line 358
Quoted 13 lines · Richard W.M. Jones
block/curl.c +1
-1@@ -352,7 +352,7 @@ static void curl_multi_timeout_do(void *arg)#endif } -static CURLState *curl_init_state (BDRVCURLState *s) +static CURLState *curl_init_state (BlockDriverState *bs,BDRVCURLState *s) {CURLState *state =NULL ;int i, j;Why add the BDRVCURLState *s argument...
Quoted 11 lines
block/curl.c static CURLState *curl_init_state(BDRVCURLState *s) · line 376
Quoted 9 lines
block/curl.c +1
-1@@ -370,7 +370,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)break ; }if (!state) { -aio_poll (state->s->aio_context, true); +aio_poll (bdrv_get_aio_context (bs), true); } }while (!state);...if it is not used?
I may be misunderstanding this, but BDRVCURLState *s is used elsewhere in the function.
However there is a potential to derive `BDRVCURLState *s = bs->opaque;' if that's what you meant?
Rich.
Signature · 4 lines
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones Read my programming and virtualization blog: http://rwmj.wordpress.com virt-builder quickly builds VMs from scratch http://libguestfs.org/virt-builder.1.html
Quoted 30 lines · Richard W.M. Jones
Quoted 17 lines · Stefan Hajnoczi
block/curl.c static void curl_multi_timeout_do(void *arg) · line 358
Quoted 13 lines · Richard W.M. Jones
block/curl.c +1
-1@@ -352,7 +352,7 @@ static void curl_multi_timeout_do(void *arg)#endif } -static CURLState *curl_init_state (BDRVCURLState *s) +static CURLState *curl_init_state (BlockDriverState *bs,BDRVCURLState *s) {CURLState *state =NULL ;int i, j;Why add the BDRVCURLState *s argument...
Quoted 11 lines
block/curl.c static CURLState *curl_init_state(BDRVCURLState *s) · line 376
Quoted 9 lines
block/curl.c +1
-1@@ -370,7 +370,7 @@ static CURLState *curl_init_state(BDRVCURLState *s)break ; }if (!state) { -aio_poll (state->s->aio_context, true); +aio_poll (bdrv_get_aio_context (bs), true); } }while (!state);...if it is not used?
Quoted 5 lines
I may be misunderstanding this, but BDRVCURLState *s is used elsewhere in the function.
However there is a potential to derive `BDRVCURLState *s =
bs->opaque;' if that's what you meant?
Sorry, I misread the code.
I thought you added s but you really added bs. That's fine and it makes sense now :).
Stefan
Stefan Hajnoczi
AppliedQuoted 5 lines · Richard W.M. Jones
No change in the patch itself since v1. However I have added a longer explanation to the commit message.
Rich.
Thanks, applied to my block tree:
https://github.com/stefanha/qemu/commits/block
Stefan