Skip to content
/ linux Public

Commit 0479268

Browse files
Lijo Lazargregkh
authored andcommitted
drm/amdgpu: Add basic validation for RAS header
commit 5df0d6a upstream. If RAS header read from EEPROM is corrupted, it could result in trying to allocate huge memory for reading the records. Add some validation to header fields. Signed-off-by: Lijo Lazar <lijo.lazar@amd.com> Reviewed-by: Hawking Zhang <Hawking.Zhang@amd.com> Signed-off-by: Alex Deucher <alexander.deucher@amd.com> [ RAS_TABLE_VER_V3 is not supported in v6.6.y. ] Signed-off-by: Alva Lan <alvalan9@foxmail.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 0ea986a commit 0479268

File tree

1 file changed

+18
-2
lines changed

1 file changed

+18
-2
lines changed

drivers/gpu/drm/amd/amdgpu/amdgpu_ras_eeprom.c

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,15 +1362,31 @@ int amdgpu_ras_eeprom_init(struct amdgpu_ras_eeprom_control *control)
13621362

13631363
__decode_table_header_from_buf(hdr, buf);
13641364

1365-
if (hdr->version == RAS_TABLE_VER_V2_1) {
1365+
switch (hdr->version) {
1366+
case RAS_TABLE_VER_V2_1:
13661367
control->ras_num_recs = RAS_NUM_RECS_V2_1(hdr);
13671368
control->ras_record_offset = RAS_RECORD_START_V2_1;
13681369
control->ras_max_record_count = RAS_MAX_RECORD_COUNT_V2_1;
1369-
} else {
1370+
break;
1371+
case RAS_TABLE_VER_V1:
13701372
control->ras_num_recs = RAS_NUM_RECS(hdr);
13711373
control->ras_record_offset = RAS_RECORD_START;
13721374
control->ras_max_record_count = RAS_MAX_RECORD_COUNT;
1375+
break;
1376+
default:
1377+
dev_err(adev->dev,
1378+
"RAS header invalid, unsupported version: %u",
1379+
hdr->version);
1380+
return -EINVAL;
13731381
}
1382+
1383+
if (control->ras_num_recs > control->ras_max_record_count) {
1384+
dev_err(adev->dev,
1385+
"RAS header invalid, records in header: %u max allowed :%u",
1386+
control->ras_num_recs, control->ras_max_record_count);
1387+
return -EINVAL;
1388+
}
1389+
13741390
control->ras_fri = RAS_OFFSET_TO_INDEX(control, hdr->first_rec_offset);
13751391

13761392
if (hdr->header == RAS_TABLE_HDR_VAL) {

0 commit comments

Comments
 (0)