diff mbox series

[1/1] iommu/amd: Fix NULL dereference bug in match_hid_uid

Message ID 20190320104138.8734-2-aaron.ma@canonical.com
State New
Headers show
Series Fix AMD IOMMU NULL dereference | expand

Commit Message

Aaron Ma March 20, 2019, 10:41 a.m. UTC
BugLink: https://bugs.launchpad.net/bugs/1820990

Add a non-NULL check to fix potential NULL pointer dereference
Cleanup code to call function once.

Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
Fixes: 2bf9a0a12749b ('iommu/amd: Add iommu support for ACPI HID devices')
Signed-off-by: Joerg Roedel <jroedel@suse.de>
(cherry picked from commit bb6bccba390c7d743c1e4427de4ef284c8cc6869)
Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
---
 drivers/iommu/amd_iommu.c | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)

Comments

Colin Ian King March 20, 2019, 10:52 a.m. UTC | #1
On 20/03/2019 10:41, Aaron Ma wrote:
> BugLink: https://bugs.launchpad.net/bugs/1820990
> 
> Add a non-NULL check to fix potential NULL pointer dereference
> Cleanup code to call function once.
> 
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> Fixes: 2bf9a0a12749b ('iommu/amd: Add iommu support for ACPI HID devices')
> Signed-off-by: Joerg Roedel <jroedel@suse.de>
> (cherry picked from commit bb6bccba390c7d743c1e4427de4ef284c8cc6869)
> Signed-off-by: Aaron Ma <aaron.ma@canonical.com>
> ---
>  drivers/iommu/amd_iommu.c | 8 ++++++--
>  1 file changed, 6 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
> index 2a7b78bb98b4..36f21b68307a 100644
> --- a/drivers/iommu/amd_iommu.c
> +++ b/drivers/iommu/amd_iommu.c
> @@ -139,10 +139,14 @@ static struct lock_class_key reserved_rbtree_key;
>  static inline int match_hid_uid(struct device *dev,
>  				struct acpihid_map_entry *entry)
>  {
> +	struct acpi_device *adev = ACPI_COMPANION(dev);
>  	const char *hid, *uid;
>  
> -	hid = acpi_device_hid(ACPI_COMPANION(dev));
> -	uid = acpi_device_uid(ACPI_COMPANION(dev));
> +	if (!adev)
> +		return -ENODEV;
> +
> +	hid = acpi_device_hid(adev);
> +	uid = acpi_device_uid(adev);
>  
>  	if (!hid || !(*hid))
>  		return -ENODEV;
> 

Looks good. Thanks.

Acked-by: Colin Ian King <colin.king@canonical.com>
Po-Hsu Lin March 20, 2019, 11:22 a.m. UTC | #2
Clean cherry-pick, and the fix itself is straightforward.
Acked-by: Po-Hsu Lin <po-hsu.lin@canonical.com>
diff mbox series

Patch

diff --git a/drivers/iommu/amd_iommu.c b/drivers/iommu/amd_iommu.c
index 2a7b78bb98b4..36f21b68307a 100644
--- a/drivers/iommu/amd_iommu.c
+++ b/drivers/iommu/amd_iommu.c
@@ -139,10 +139,14 @@  static struct lock_class_key reserved_rbtree_key;
 static inline int match_hid_uid(struct device *dev,
 				struct acpihid_map_entry *entry)
 {
+	struct acpi_device *adev = ACPI_COMPANION(dev);
 	const char *hid, *uid;
 
-	hid = acpi_device_hid(ACPI_COMPANION(dev));
-	uid = acpi_device_uid(ACPI_COMPANION(dev));
+	if (!adev)
+		return -ENODEV;
+
+	hid = acpi_device_hid(adev);
+	uid = acpi_device_uid(adev);
 
 	if (!hid || !(*hid))
 		return -ENODEV;