]> git.proxmox.com Git - mirror_ubuntu-kernels.git/commitdiff
drm/amdgpu: Fix potential out-of-bounds access in 'amdgpu_discovery_reg_base_init()'
authorSrinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Thu, 1 Feb 2024 17:17:15 +0000 (22:47 +0530)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 7 Feb 2024 17:26:22 +0000 (12:26 -0500)
The issue arises when the array 'adev->vcn.vcn_config' is accessed
before checking if the index 'adev->vcn.num_vcn_inst' is within the
bounds of the array.

The fix involves moving the bounds check before the array access. This
ensures that 'adev->vcn.num_vcn_inst' is within the bounds of the array
before it is used as an index.

Fixes the below:
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c:1289 amdgpu_discovery_reg_base_init() error: testing array offset 'adev->vcn.num_vcn_inst' after use.

Fixes: a0ccc717c4ab ("drm/amdgpu/discovery: validate VCN and SDMA instances")
Cc: Christian König <christian.koenig@amd.com>
Cc: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Srinivasan Shanmugam <srinivasan.shanmugam@amd.com>
Reviewed-by: Alex Deucher <alexander.deucher@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_discovery.c

index 7ed1b9fb4605283110d322b4d68248faf9ee3dd0..118288b644870235d66a8ccde39db42e40eda06f 100644 (file)
@@ -1282,11 +1282,10 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
                                 *     0b10 : encode is disabled
                                 *     0b01 : decode is disabled
                                 */
-                               adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
-                                       ip->revision & 0xc0;
-                               ip->revision &= ~0xc0;
                                if (adev->vcn.num_vcn_inst <
                                    AMDGPU_MAX_VCN_INSTANCES) {
+                                       adev->vcn.vcn_config[adev->vcn.num_vcn_inst] =
+                                               ip->revision & 0xc0;
                                        adev->vcn.num_vcn_inst++;
                                        adev->vcn.inst_mask |=
                                                (1U << ip->instance_number);
@@ -1297,6 +1296,7 @@ static int amdgpu_discovery_reg_base_init(struct amdgpu_device *adev)
                                                adev->vcn.num_vcn_inst + 1,
                                                AMDGPU_MAX_VCN_INSTANCES);
                                }
+                               ip->revision &= ~0xc0;
                        }
                        if (le16_to_cpu(ip->hw_id) == SDMA0_HWID ||
                            le16_to_cpu(ip->hw_id) == SDMA1_HWID ||