From: P J P <ppandit@redhat.com>
To: QEMU Developers <qemu-devel@nongnu.org>
Cc: Peter Maydell <peter.maydell@linaro.org>,
John Snow <jsnow@redhat.com>,
Prasad J Pandit <pjp@fedoraproject.org>,
Zuozhi fzz <zuozhi.fzz@alibaba-inc.com>
Subject: [Qemu-devel] [PATCH v2] ide: ahci: add check before calling dma_memory_unmap
Date: Fri, 29 Jan 2016 01:18:50 +0530 [thread overview]
Message-ID: <1454010530-16804-1-git-send-email-ppandit@redhat.com> (raw)
From: Prasad J Pandit <pjp@fedoraproject.org>
When IDE AHCI emulation uses Frame Information Structures(FIS)
engine for data transfer, the mapped FIS buffer address is stored
in a static 'bounce.buffer'. When a request is made to map another
memory region, address_space_map() returns NULL because
'bounce.buffer' is in_use. It leads to a null pointer dereference
error while doing 'dma_memory_unmap'. Add a check to avoid it.
Reported-by: Zuozhi fzz <zuozhi.fzz@alibaba-inc.com>
Signed-off-by: Prasad J Pandit <pjp@fedoraproject.org>
---
hw/ide/ahci.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
Update as per review
-> https://lists.gnu.org/archive/html/qemu-devel/2016-01/msg05715.html
diff --git a/hw/ide/ahci.c b/hw/ide/ahci.c
index 17f1cbd..f413a59 100644
--- a/hw/ide/ahci.c
+++ b/hw/ide/ahci.c
@@ -661,9 +661,11 @@ static bool ahci_map_fis_address(AHCIDevice *ad)
static void ahci_unmap_fis_address(AHCIDevice *ad)
{
- dma_memory_unmap(ad->hba->as, ad->res_fis, 256,
- DMA_DIRECTION_FROM_DEVICE, 256);
- ad->res_fis = NULL;
+ if (ad->res_fis) {
+ dma_memory_unmap(ad->hba->as, ad->res_fis, 256,
+ DMA_DIRECTION_FROM_DEVICE, 256);
+ ad->res_fis = NULL;
+ }
}
static bool ahci_map_clb_address(AHCIDevice *ad)
@@ -677,9 +679,11 @@ static bool ahci_map_clb_address(AHCIDevice *ad)
static void ahci_unmap_clb_address(AHCIDevice *ad)
{
- dma_memory_unmap(ad->hba->as, ad->lst, 1024,
- DMA_DIRECTION_FROM_DEVICE, 1024);
- ad->lst = NULL;
+ if (ad->lst) {
+ dma_memory_unmap(ad->hba->as, ad->lst, 1024,
+ DMA_DIRECTION_FROM_DEVICE, 1024);
+ ad->lst = NULL;
+ }
}
static void ahci_write_fis_sdb(AHCIState *s, NCQTransferState *ncq_tfs)
--
2.5.0
next reply other threads:[~2016-01-28 19:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-01-28 19:48 P J P [this message]
2016-01-28 19:57 ` [Qemu-devel] [PATCH v2] ide: ahci: add check before calling dma_memory_unmap John Snow
2016-01-28 20:41 ` Paolo Bonzini
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=1454010530-16804-1-git-send-email-ppandit@redhat.com \
--to=ppandit@redhat.com \
--cc=jsnow@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=pjp@fedoraproject.org \
--cc=qemu-devel@nongnu.org \
--cc=zuozhi.fzz@alibaba-inc.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 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).