All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Evgenii Burenchev" <evg28bur@yandex.ru>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH 6.1] drm/amdgpu: Use scnprintf() in amdgpu_mes_add_ring()
Date: Thu, 09 Jul 2026 11:49:25 +0000	[thread overview]
Message-ID: <20260709114926.696611F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260709112825.40016-1-evg28bur@yandex.ru>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] Double unlock of `adev->mes` mutex in error path.
- [High] Unchecked NULL fence pointers passed to `dma_fence_wait()`.
--

--- Patch [1]: [PATCH 6.1] drm/amdgpu: Use scnprintf() in amdgpu_mes_add_ring() ---
commit a3f6095725ba7df26135d6b5a8b649631f54d76e
Author: Evgenii Burenchev <evg28bur@yandex.ru>

drm/amdgpu: Use scnprintf() in amdgpu_mes_add_ring()

Replace sprintf() with scnprintf() to prevent a potential buffer overflow
when writing to ring->name.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> index 0c546245793b9..41e699f4b5d2e 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_mes.c
> @@ -1053,13 +1053,14 @@ int amdgpu_mes_add_ring(struct amdgpu_device *adev, int gang_id,
>  	ring->doorbell_index = qprops.doorbell_off;
>  
>  	if (queue_type == AMDGPU_RING_TYPE_GFX)

[Severity: High]
This is a pre-existing issue, but I noticed a potential NULL pointer
dereference just before this code in amdgpu_mes_add_ring():

	dma_fence_wait(gang->process->vm->last_update, false);
	dma_fence_wait(ctx_data->meta_data_va->last_pt_update, false);

If the fences are unallocated, these pointers might be NULL. The
dma_fence_wait() function does not check for NULL inputs before dereferencing.
Could this result in a kernel oops during normal process/gang queue creation?

[Severity: High]
This is a pre-existing issue, but I also noticed a potential double unlock
of the adev->mes mutex. Before the new scnprintf() code, we unlock it here:

	amdgpu_mes_unlock(&adev->mes);

	r = amdgpu_mes_add_hw_queue(adev, gang_id, &qprops, &queue_id);
	if (r)
		goto clean_up_ring;

If amdgpu_mes_add_hw_queue() fails, it jumps to clean_up_ring, which falls
through to clean_up_memory:

clean_up_memory:
	kfree(ring);
	amdgpu_mes_unlock(&adev->mes);
	return r;

Will this second call to amdgpu_mes_unlock() cause a double unlock panic or
state corruption since the mutex was already dropped?

> -		sprintf(ring->name, "gfx_%d.%d.%d", pasid, gang_id, queue_id);
> +		scnprintf(ring->name, sizeof(ring->name), "gfx_%d.%d.%d",
> +			pasid, gang_id, queue_id);
>  	else if (queue_type == AMDGPU_RING_TYPE_COMPUTE)
> -		sprintf(ring->name, "compute_%d.%d.%d", pasid, gang_id,
> -			queue_id);
> +		scnprintf(ring->name, sizeof(ring->name), "compute_%d.%d.%d",
> +			pasid, gang_id, queue_id);
>  	else if (queue_type == AMDGPU_RING_TYPE_SDMA)
> -		sprintf(ring->name, "sdma_%d.%d.%d", pasid, gang_id,
> -			queue_id);
> +		scnprintf(ring->name, sizeof(ring->name), "sdma_%d.%d.%d",
> +			pasid, gang_id, queue_id);
>  	else
>  		BUG();
>

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20260709112825.40016-1-evg28bur@yandex.ru?part=1

  reply	other threads:[~2026-07-09 11:49 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-09 11:28 [PATCH 6.1] drm/amdgpu: Use scnprintf() in amdgpu_mes_add_ring() Evgenii Burenchev
2026-07-09 11:49 ` sashiko-bot [this message]
2026-07-09 12:02 ` Christian König

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=20260709114926.696611F000E9@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=evg28bur@yandex.ru \
    --cc=sashiko-reviews@lists.linux.dev \
    /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.