iommu/amd: Check if domain is NULL in get_domain() and return -EBUSY
authorBaoquan He <bhe@redhat.com>
Thu, 24 Aug 2017 13:13:57 +0000 (21:13 +0800)
committerJoerg Roedel <jroedel@suse.de>
Mon, 28 Aug 2017 09:28:37 +0000 (11:28 +0200)
In get_domain(), 'domain' could be NULL before it's passed to dma_ops_domain()
to dereference. And the current code calling get_domain() can't deal with the
returned 'domain' well if its value is NULL.

So before dma_ops_domain() calling, check if 'domain' is NULL, If yes just return
ERR_PTR(-EBUSY) directly.

Reported-by: Dan Carpenter <dan.carpenter@oracle.com>
Fixes: df3f7a6e8e85 ('iommu/amd: Use is_attach_deferred call-back')
Signed-off-by: Baoquan He <bhe@redhat.com>
Signed-off-by: Joerg Roedel <jroedel@suse.de>
drivers/iommu/amd_iommu.c

index 9e8ea190779606d4ce07657fa688f54e68676f22..b531307a9360a3d245f043dc8b39ca9de74442f3 100644 (file)
@@ -2472,6 +2472,9 @@ static struct protection_domain *get_domain(struct device *dev)
                domain = to_pdomain(io_domain);
                attach_device(dev, domain);
        }
+       if (domain == NULL)
+               return ERR_PTR(-EBUSY);
+
        if (!dma_ops_domain(domain))
                return ERR_PTR(-EBUSY);