From 8af267eb00ffd55419996358935fdff1616616a8 Mon Sep 17 00:00:00 2001 From: Yiwei Zhang Date: Fri, 8 Mar 2024 00:55:10 -0800 Subject: [PATCH] venus: fix ffb batch prepare for a corner case and avoid a memcpy UB Batches must be ignored if batch count is zero, so all batch inspections have to be gated behind batch count. For memcpy, it's UB if either src or dst is NULL even when size is zero. Side note: - For original commit, this fixes just the memcpy UB - For current codes, this fixes to not skip ffb batch prepare Fixes: 493a3b5cdaf ("venus: refactor batch submission fixup") Signed-off-by: Yiwei Zhang Part-of: --- src/virtio/vulkan/vn_queue.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/virtio/vulkan/vn_queue.c b/src/virtio/vulkan/vn_queue.c index 7da1521b405..54f255c2118 100644 --- a/src/virtio/vulkan/vn_queue.c +++ b/src/virtio/vulkan/vn_queue.c @@ -807,7 +807,7 @@ vn_queue_submission_setup_batches(struct vn_queue_submission *submit) * - non-empty: copy batches for adding feedbacks * - empty: initialize a batch for fence feedback */ - if (submit->batches) { + if (submit->batch_count) { memcpy(submit->temp.batches, submit->batches, vn_get_batch_size(submit) * submit->batch_count); } else {