]> git.itanic.dy.fi Git - linux-stable/commitdiff
drm/amdgpu: Fix potential double free and null pointer dereference
authorLiang He <windhl@126.com>
Tue, 22 Nov 2022 04:28:49 +0000 (12:28 +0800)
committerAlex Deucher <alexander.deucher@amd.com>
Tue, 29 Nov 2022 16:03:37 +0000 (11:03 -0500)
In amdgpu_get_xgmi_hive(), we should not call kfree() after
kobject_put() as the PUT will call kfree().

In amdgpu_device_ip_init(), we need to check the returned *hive*
which can be NULL before we dereference it.

Signed-off-by: Liang He <windhl@126.com>
Reviewed-by: Luben Tuikov <luben.tuikov@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
drivers/gpu/drm/amd/amdgpu/amdgpu_xgmi.c

index 9f7741871bb4891dfe9fbc795a436aa570c74dd4..cfa411c12072421d348d91a2a1332b1c7c7a6596 100644 (file)
@@ -2473,6 +2473,11 @@ static int amdgpu_device_ip_init(struct amdgpu_device *adev)
                        if (!amdgpu_sriov_vf(adev)) {
                                struct amdgpu_hive_info *hive = amdgpu_get_xgmi_hive(adev);
 
+                               if (WARN_ON(!hive)) {
+                                       r = -ENOENT;
+                                       goto init_failed;
+                               }
+
                                if (!hive->reset_domain ||
                                    !amdgpu_reset_get_reset_domain(hive->reset_domain)) {
                                        r = -ENOENT;
index 47159e9a08848c72125bb9a6cc81b7c316d5e426..4b9e7b050ccd25fe5a33cba18c04e5829a46d8ad 100644 (file)
@@ -386,7 +386,6 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
        if (ret) {
                dev_err(adev->dev, "XGMI: failed initializing kobject for xgmi hive\n");
                kobject_put(&hive->kobj);
-               kfree(hive);
                hive = NULL;
                goto pro_end;
        }
@@ -410,7 +409,6 @@ struct amdgpu_hive_info *amdgpu_get_xgmi_hive(struct amdgpu_device *adev)
                                dev_err(adev->dev, "XGMI: failed initializing reset domain for xgmi hive\n");
                                ret = -ENOMEM;
                                kobject_put(&hive->kobj);
-                               kfree(hive);
                                hive = NULL;
                                goto pro_end;
                        }