From: sashiko-bot@kernel.org
To: "Baineng Shou" <shoubaineng@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH] dma-buf/test: add KUnit case for dma_fence_dedup_array() empty input
Date: Tue, 30 Jun 2026 06:13:29 +0000 [thread overview]
Message-ID: <20260630061329.DE3131F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260630060436.1527498-1-shoubaineng@gmail.com>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
New issues:
- [Medium] The newly added test_dedup_empty KUnit test will unconditionally fail, breaking CI.
Pre-existing issues:
- [Critical] dma_fence_dedup_array() incorrectly returns 1 for an empty array, causing uninitialized memory dereference in amdgpu_userq_wait_return_fence_info().
--
commit 693b63d34624f1aa69f2c97819d4a6d6655ec6bc
Author: Baineng Shou <shoubaineng@gmail.com>
dma-buf/test: add KUnit case for dma_fence_dedup_array() empty input
This commit adds a KUnit test case to verify that dma_fence_dedup_array()
returns 0 when provided with an empty array. The test aims to ensure the
documented contract is enforced and prevents future regressions.
> diff --git a/drivers/dma-buf/st-dma-fence-unwrap.c b/drivers/dma-buf/st-dma-fence-unwrap.c
> index 4e7ee25372ba6..72dea6091d583 100644
> --- a/drivers/dma-buf/st-dma-fence-unwrap.c
> +++ b/drivers/dma-buf/st-dma-fence-unwrap.c
[ ... ]
> @@ -370,6 +370,15 @@ static void test_unwrap_merge_seqno(struct kunit *test)
> dma_fence_put(f1);
> }
>
> +static void test_dedup_empty(struct kunit *test)
> +{
> + struct dma_fence *fence[1] = { NULL };
> + int ret;
> +
> + ret = dma_fence_dedup_array(fence, 0);
> + KUNIT_EXPECT_EQ(test, ret, 0);
[Severity: Medium]
Will this test fail unconditionally on the current tree?
Looking at dma_fence_dedup_array() in drivers/dma-buf/dma-fence-unwrap.c,
there is no early return for an empty array:
int dma_fence_dedup_array(struct dma_fence **fences, int num_fences)
{
int i, j;
sort(fences, num_fences, sizeof(*fences), fence_cmp, NULL);
j = 0;
for (i = 1; i < num_fences; i++) {
...
}
return ++j;
}
The loop condition i < num_fences is skipped when num_fences is 0, but the
function ends with return ++j, which returns 1. Since this patch adds a
KUnit expectation for 0, won't this cause CI to break until the corresponding
fix for dma_fence_dedup_array() is actually applied to the tree?
[Severity: Critical]
This is a pre-existing issue, but does dma_fence_dedup_array() returning 1
for empty arrays cause an uninitialized memory dereference in other
subsystems?
For example, in drivers/gpu/drm/amd/amdgpu/amdgpu_userq_fence.c:
amdgpu_userq_wait_return_fence_info() uses kmalloc_array for the fences array
and eventually calls dma_fence_dedup_array:
num_fences = dma_fence_dedup_array(fences, num_fences);
waitq = amdgpu_userq_get(userq_mgr, wait_info->waitq_id);
if (!waitq) {
...
for (i = 0, cnt = 0; i < num_fences; i++) {
struct amdgpu_userq_fence_driver *fence_drv;
struct amdgpu_userq_fence *userq_fence;
u32 index;
userq_fence = to_amdgpu_userq_fence(fences[i]);
If an unprivileged user triggers a path via ioctl where 0 fences are populated
but dma_fence_dedup_array() is called with num_fences = 0, returning 1 will
cause the subsequent loop to iterate once. Will this dereference an
uninitialized garbage pointer from kmalloc_array() when to_amdgpu_userq_fence()
evaluates fences[i]?
> +}
> +
> static void test_unwrap_merge_order(struct kunit *test)
[ ... ]
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260630060436.1527498-1-shoubaineng@gmail.com?part=1
next prev parent reply other threads:[~2026-06-30 6:13 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-06-30 6:04 [PATCH] dma-buf/test: add KUnit case for dma_fence_dedup_array() empty input Baineng Shou
2026-06-30 6:13 ` sashiko-bot [this message]
2026-06-30 8:29 ` Christian König
2026-06-30 8:49 ` 寿柏能
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20260630061329.DE3131F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=shoubaineng@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.