Skip to contentSkip to conversation

drm/amd/amdgpu: prevent CPER rsp batch index out of bound

PATCH In review Bokun Zhang 2 participants 2 messages Jun 25 – Jun 29

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 4/4 drm/amd/amdgpu: prevent CPER rsp batch index out of bound

- There is a bug that the host CPER response struct may contain bad data so that it will lead to guest side memory access out of bound

- Must move the variable to a dedicated variable
and compare the boundary

---
 drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c +6 -1
index c6e7aa6ecb8f..6049b3392a9d 100644
@@ -204,6 +204,7 @@ static int amdgpu_virt_ras_get_batch_records(struct ras_core_context *ras_core,
 		.batch_num = RAS_CMD_MAX_BATCH_NUM,
 	};
 	struct ras_cmd_batch_trace_record_rsp *rsp = rsp_cache;
+	uint32_t rsp_start_batch_id;
 	struct batch_ras_trace_info *batch;
 	uint32_t trace_num;
 	uint32_t offset;
@@ -220,7 +221,11 @@ static int amdgpu_virt_ras_get_batch_records(struct ras_core_context *ras_core,
 			return -EPIPE;
 	}
 
-	batch = &rsp->batchs[batch_id - rsp->start_batch_id];
+	rsp_start_batch_id = rsp->start_batch_id;
+	if ((batch_id < rsp_start_batch_id) || ((batch_id - rsp_start_batch_id) >= RAS_CMD_MAX_BATCH_NUM))
+		return -ENODATA;
+
+	batch = &rsp->batchs[batch_id - rsp_start_batch_id];
 	if (batch_id != batch->batch_id)
 		return -ENODATA;
 
Signature · 1 line
2.51.0
Reviewed-by on v1 4/4
#1 lore raw
Quoted 9 lines · Bokun Zhang

- There is a bug that the host CPER response struct may contain bad data so that it will lead to guest side memory access out of bound

- Must move the variable to a dedicated variable
and compare the boundary

Series is:

Quoted 32 lines
---
 drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c +6 -2
index c6e7aa6ecb8f..6049b3392a9d 100644
@@ -204,6 +204,7 @@ static int amdgpu_virt_ras_get_batch_records(struct ras_core_context *ras_core,
                .batch_num = RAS_CMD_MAX_BATCH_NUM,
        };
        struct ras_cmd_batch_trace_record_rsp *rsp = rsp_cache;
+       uint32_t rsp_start_batch_id;
        struct batch_ras_trace_info *batch;
        uint32_t trace_num;
        uint32_t offset;
@@ -220,7 +221,11 @@ static int amdgpu_virt_ras_get_batch_records(struct ras_core_context *ras_core,
                        return -EPIPE;
        }
 
-       batch = &rsp->batchs[batch_id - rsp->start_batch_id];
+       rsp_start_batch_id = rsp->start_batch_id;
+       if ((batch_id < rsp_start_batch_id) || ((batch_id - rsp_start_batch_id) >= RAS_CMD_MAX_BATCH_NUM))
+               return -ENODATA;
+
+       batch = &rsp->batchs[batch_id - rsp_start_batch_id];
        if (batch_id != batch->batch_id)
                return -ENODATA;
 
--

2.51.0