qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync
@ 2017-07-14 10:00 P J P
  2017-07-17  9:49 ` Stefan Hajnoczi
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: P J P @ 2017-07-14 10:00 UTC (permalink / raw)
  To: Qemu Developers; +Cc: John Snow, qemu-block, Chensongnian, Prasad J Pandit

From: Prasad J Pandit <pjp@fedoraproject.org>

When cancelling pending DMA requests in ide_cancel_dma_sync,
the s->blk object could be null, leading to a null dereference.
Add check to avoid it.

Reported-by: Chensongnian <chensongnian@huawei.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
 hw/ide/core.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/hw/ide/core.c b/hw/ide/core.c
index 0b48b64..04474b3 100644
--- a/hw/ide/core.c
+++ b/hw/ide/core.c
@@ -681,8 +681,10 @@ void ide_cancel_dma_sync(IDEState *s)
 #ifdef DEBUG_IDE
         printf("%s: draining all remaining requests", __func__);
 #endif
-        blk_drain(s->blk);
-        assert(s->bus->dma->aiocb == NULL);
+        if (s->blk) {
+            blk_drain(s->blk);
+            assert(s->bus->dma->aiocb == NULL);
+        }
     }
 }
 
-- 
2.9.4

^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync
  2017-07-14 10:00 [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync P J P
@ 2017-07-17  9:49 ` Stefan Hajnoczi
  2017-07-17 16:47 ` Philippe Mathieu-Daudé
  2017-07-19 18:49 ` John Snow
  2 siblings, 0 replies; 4+ messages in thread
From: Stefan Hajnoczi @ 2017-07-17  9:49 UTC (permalink / raw)
  To: P J P; +Cc: Qemu Developers, John Snow, Chensongnian, qemu-block,
	Prasad J Pandit

[-- Attachment #1: Type: text/plain, Size: 1122 bytes --]

On Fri, Jul 14, 2017 at 03:30:29PM +0530, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
> 
> When cancelling pending DMA requests in ide_cancel_dma_sync,
> the s->blk object could be null, leading to a null dereference.
> Add check to avoid it.

Please include details on how to reproduce the bug and/or which code
path triggers this NULL dereference.

> Reported-by: Chensongnian <chensongnian@huawei.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
>  hw/ide/core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 0b48b64..04474b3 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -681,8 +681,10 @@ void ide_cancel_dma_sync(IDEState *s)
>  #ifdef DEBUG_IDE
>          printf("%s: draining all remaining requests", __func__);
>  #endif
> -        blk_drain(s->blk);
> -        assert(s->bus->dma->aiocb == NULL);
> +        if (s->blk) {
> +            blk_drain(s->blk);
> +            assert(s->bus->dma->aiocb == NULL);
> +        }
>      }
>  }
>  
> -- 
> 2.9.4
> 
> 

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 455 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync
  2017-07-14 10:00 [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync P J P
  2017-07-17  9:49 ` Stefan Hajnoczi
@ 2017-07-17 16:47 ` Philippe Mathieu-Daudé
  2017-07-19 18:49 ` John Snow
  2 siblings, 0 replies; 4+ messages in thread
From: Philippe Mathieu-Daudé @ 2017-07-17 16:47 UTC (permalink / raw)
  To: P J P
  Cc: Qemu Developers, John Snow, Chensongnian,
	open list:Block layer core, Prasad J Pandit

On Fri, Jul 14, 2017 at 7:00 AM, P J P <ppandit@redhat.com> wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
> -        blk_drain(s->blk);
> -        assert(s->bus->dma->aiocb == NULL);

This assert looks weird

> +        if (s->blk) {
> +            blk_drain(s->blk);
> +            assert(s->bus->dma->aiocb == NULL);
> +        }

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync
  2017-07-14 10:00 [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync P J P
  2017-07-17  9:49 ` Stefan Hajnoczi
  2017-07-17 16:47 ` Philippe Mathieu-Daudé
@ 2017-07-19 18:49 ` John Snow
  2 siblings, 0 replies; 4+ messages in thread
From: John Snow @ 2017-07-19 18:49 UTC (permalink / raw)
  To: P J P, Qemu Developers; +Cc: Chensongnian, qemu-block, Prasad J Pandit



On 07/14/2017 06:00 AM, P J P wrote:
> From: Prasad J Pandit <pjp@fedoraproject.org>
> 
> When cancelling pending DMA requests in ide_cancel_dma_sync,
> the s->blk object could be null, leading to a null dereference.
> Add check to avoid it.
> 
> Reported-by: Chensongnian <chensongnian@huawei.com>
> Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
> ---
>  hw/ide/core.c | 6 ++++--
>  1 file changed, 4 insertions(+), 2 deletions(-)
> 
> diff --git a/hw/ide/core.c b/hw/ide/core.c
> index 0b48b64..04474b3 100644
> --- a/hw/ide/core.c
> +++ b/hw/ide/core.c
> @@ -681,8 +681,10 @@ void ide_cancel_dma_sync(IDEState *s)
>  #ifdef DEBUG_IDE
>          printf("%s: draining all remaining requests", __func__);
>  #endif
> -        blk_drain(s->blk);
> -        assert(s->bus->dma->aiocb == NULL);
> +        if (s->blk) {
> +            blk_drain(s->blk);
> +            assert(s->bus->dma->aiocb == NULL);
> +        }
>      }
>  }
>  
> 

I guess this occurs through

ide_exec_cmd
  cmd_device_reset
    ide_cancel_dma_sync

though if s->blk does not exist, we should usually not be able to
address this device with a reset command as such. (core.c:2021) -- but
this is only for secondary devices. I guess we don't guard against
nonexistent primary devices......?

Further, how do we have s->bus->dma->aiocb if there's no blk device?
What DMA request did we accept...?

Can you please submit a stack that illustrates the code path followed so
this fix can be properly verified and tested?

Thanks,
--John

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2017-07-19 18:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-14 10:00 [Qemu-devel] [PATCH] ide: check BlockBackend object in ide_cancel_dma_sync P J P
2017-07-17  9:49 ` Stefan Hajnoczi
2017-07-17 16:47 ` Philippe Mathieu-Daudé
2017-07-19 18:49 ` John Snow

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).