iommu.lists.linux-foundation.org archive mirror
 help / color / mirror / Atom feed
From: Baoquan He <bhe@redhat.com>
To: iommu@lists.linux-foundation.org, linux-kernel@vger.kernel.org
Cc: dan.carpenter@oracle.com, joro@8bytes.org, Baoquan He <bhe@redhat.com>
Subject: [PATCH] iommu/amd: Check if domain is NULL before dereference it
Date: Thu, 24 Aug 2017 19:56:47 +0800	[thread overview]
Message-ID: <1503575807-15746-1-git-send-email-bhe@redhat.com> (raw)

In get_domain(), 'domain' could still be NULL before it's passed to
dma_ops_domain() to dereference. For safety, check if 'domain' is
NULL before passing to dma_ops_domain().

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Signed-off-by: Baoquan He <bhe@redhat.com>
---
 drivers/iommu/amd_iommu.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 16f1e6af00b0..2e2d5e6a13b3 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -2262,7 +2262,7 @@ static struct protection_domain *get_domain(struct device *dev)
 		domain = to_pdomain(io_domain);
 		attach_device(dev, domain);
 	}
-	if (!dma_ops_domain(domain))
+	if (domain && !dma_ops_domain(domain))
 		return ERR_PTR(-EBUSY);
 
 	return domain;
-- 
2.5.5

             reply	other threads:[~2017-08-24 11:56 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-08-24 11:56 Baoquan He [this message]
     [not found] ` <1503575807-15746-1-git-send-email-bhe-H+wXaHxf7aLQT0dZR+AlfA@public.gmane.org>
2017-08-24 12:11   ` [PATCH] iommu/amd: Check if domain is NULL before dereference it Dan Carpenter
2017-08-24 12:22     ` Baoquan He
2017-08-24 12:32       ` Dan Carpenter
2017-08-24 12:47         ` Baoquan He
2017-08-24 12:53           ` Dan Carpenter
2017-08-24 13:01             ` Baoquan He

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=1503575807-15746-1-git-send-email-bhe@redhat.com \
    --to=bhe@redhat.com \
    --cc=dan.carpenter@oracle.com \
    --cc=iommu@lists.linux-foundation.org \
    --cc=joro@8bytes.org \
    --cc=linux-kernel@vger.kernel.org \
    /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).