drm/amd/ras: bound CPER record fetch buffer size and count
Subsystems (2)
PATCH 1/4 drm/amd/ras: bound CPER record fetch buffer size and count
Limit RAS_CMD__GET_CPER_RECORD so buf_size and cper_num from userspace cannot force unbounded kzalloc or long loops.
Signed-off-by Candice Li <[email protected]>
--- drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c | 4 ++++ drivers/gpu/drm/amd/ras/rascore/ras_cmd.c | 4 ++++ drivers/gpu/drm/amd/ras/rascore/ras_cmd.h | 4 ++++ 3 files changed, 12 insertions(+)
drivers/gpu/drm/amd/ras/ras_mgr/amdgpu_virt_ras_cmd.c +4 -0
@@ -267,6 +267,10 @@ static int amdgpu_virt_ras_get_cper_records(struct ras_core_context *ras_core,if (!req->buf_size || !req->buf_ptr || !req->cper_num)return RAS_CMD__ERROR_INVALID_INPUT_DATA ; +if (req->buf_size >RAS_CMD_MAX_CPER_BUF_SZ || + req->cper_num >RAS_CMD_MAX_CPER_FETCH_NUM ) +return RAS_CMD__ERROR_INVALID_INPUT_DATA ; + trace =kcalloc (MAX_RECORD_PER_BATCH ,sizeof (*trace),GFP_KERNEL );if (!trace)return RAS_CMD__ERROR_GENERIC ;
drivers/gpu/drm/amd/ras/rascore/ras_cmd.c +4 -0
@@ -217,6 +217,10 @@ static int ras_cmd_get_cper_records(struct ras_core_context *ras_core,if (!req->buf_size || !req->buf_ptr || !req->cper_num)return RAS_CMD__ERROR_INVALID_INPUT_DATA ; +if (req->buf_size >RAS_CMD_MAX_CPER_BUF_SZ || + req->cper_num >RAS_CMD_MAX_CPER_FETCH_NUM ) +return RAS_CMD__ERROR_INVALID_INPUT_DATA ; + buffer =kzalloc (req->buf_size,GFP_KERNEL );if (!buffer)return RAS_CMD__ERROR_GENERIC ;
drivers/gpu/drm/amd/ras/rascore/ras_cmd.h +4 -0
@@ -405,6 +405,10 @@ struct batch_ras_trace_info {#define RAS_CMD_MAX_BATCH_NUM 300#define RAS_CMD_MAX_TRACE_NUM 300 + +/* Upper bounds for RAS_CMD__GET_CPER_RECORD to limit kernel allocations and work. */ +#define RAS_CMD_MAX_CPER_FETCH_NUM RAS_CMD_MAX_BATCH_NUM +#define RAS_CMD_MAX_CPER_BUF_SZ (1024U * 1024U)/* 1 MiB */ struct ras_cmd_batch_trace_record_rsp {uint32_t version;uint16_t real_batch_num;
Signature · 1 line
2.25.1