From 23948df34dc798cf21b40bf15d76a8035c6e01f0 Mon Sep 17 00:00:00 2001 From: notaz Date: Sun, 27 Aug 2023 23:21:36 +0300 Subject: [PATCH] gpulib: don't corrupt memory on garbage commands --- plugins/gpulib/gpu.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/plugins/gpulib/gpu.c b/plugins/gpulib/gpu.c index b23f8a88..9cf5841d 100644 --- a/plugins/gpulib/gpu.c +++ b/plugins/gpulib/gpu.c @@ -614,6 +614,10 @@ long GPUdmaChain(uint32_t *rambase, uint32_t start_addr, uint32_t *progress_addr log_io(".chain %08lx #%d+%d\n", (long)(list - rambase) * 4, len, gpu.cmd_len); if (unlikely(gpu.cmd_len > 0)) { + if (gpu.cmd_len + len > ARRAY_SIZE(gpu.cmd_buffer)) { + log_anomaly("cmd_buffer overflow, likely garbage commands\n"); + gpu.cmd_len = 0; + } memcpy(gpu.cmd_buffer + gpu.cmd_len, list + 1, len * 4); gpu.cmd_len += len; flush_cmd_buffer(); -- 2.39.5