drm/amdgpu: avoid a possible array overflow
authorAlex Deucher <alexander.deucher@amd.com>
Wed, 24 Aug 2016 16:31:36 +0000 (12:31 -0400)
committerAlex Deucher <alexander.deucher@amd.com>
Wed, 24 Aug 2016 18:04:24 +0000 (14:04 -0400)
When looking up the connector type make sure the index
is valid.  Avoids a later crash if we read past the end
of the array.

Workaround for bug:
https://bugs.freedesktop.org/show_bug.cgi?id=97460

Reviewed-by: Christian König <christian.koenig@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
Cc: stable@vger.kernel.org
drivers/gpu/drm/amd/amdgpu/amdgpu_atombios.c

index 983175363b0688df6ca181e612000173da9141bf..151422307d31751d4359160d15993c337a04d0f0 100644 (file)
@@ -321,6 +321,12 @@ bool amdgpu_atombios_get_connector_info_from_object_table(struct amdgpu_device *
                            (le16_to_cpu(path->usConnObjectId) &
                             OBJECT_TYPE_MASK) >> OBJECT_TYPE_SHIFT;
 
+                       if (con_obj_id >= ARRAY_SIZE(object_connector_convert)) {
+                               DRM_ERROR("invalid con_obj_id %d for device tag 0x%04x\n",
+                                         con_obj_id, le16_to_cpu(path->usDeviceTag));
+                               continue;
+                       }
+
                        connector_type =
                                object_connector_convert[con_obj_id];
                        connector_object_id = con_obj_id;