All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Lin Huiyi" <xinghui79@qq.com>
Cc: amd-gfx@lists.freedesktop.org, dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v5] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
Date: Tue, 01 Dec 2026 08:39:39 +0000	[thread overview]
Message-ID: <sashiko-outbox-242865@kernel.org> (raw)
In-Reply-To: <tencent_B6D678900EAF7134FB708499EF1A13E93608@qq.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] drm/amdgpu: flawed mgpu_info.num_gpu check in
  __check_local_vpod_integrity()
--

commit 5534f8d736ae8e09c0ee2bd1e6fbe48b3f50a027
Author: Lin Huiyi <xinghui79@qq.com>

drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check

This commit bounds-checks mgpu_info.num_gpu against
AMDGPU_UALINK_LOCAL_ACCELS_MAX in __check_local_vpod_integrity() and limits
the peer_info->local_accels memcpy() to the populated entries.

> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> index fa4c3d27d2720..c0016e8815e93 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
> @@ -1162,6 +1162,18 @@ static int __check_local_vpod_integrity(struct amdgpu_device *adev)
>  	__set_bit(info->ppod.accel_id, local_accel_ids);
>  	local_accels[n_local_accels++] = info->ppod.accel_id;
>  
> +	/*
> +	 * local_accels[] holds the local GPU itself plus one entry per peer.
> +	 * The platform never exposes more than AMDGPU_UALINK_LOCAL_ACCELS_MAX
> +	 * local GPUs, so reject a configuration that cannot fit.
> +	 */
> +	if (unlikely(mgpu_info.num_gpu > AMDGPU_UALINK_LOCAL_ACCELS_MAX)) {
> +		dev_warn(adev->dev,
> +			 "UALINK: integrity fail: too many local GPUs: %u (max %u)\n",
> +			 mgpu_info.num_gpu, AMDGPU_UALINK_LOCAL_ACCELS_MAX);
> +		return -EINVAL;
> +	}
> +
>  	for (i = 0; i < mgpu_info.num_gpu; i++) {
>  		peer_adev = mgpu_info.gpu_ins[i].adev;
>  		if (peer_adev == adev || !peer_adev->ualink.info)

[Severity: Medium]
Can this still overflow local_accels[] and peer_info->local_accels[] by one
element, while also rejecting valid vPods when other AMD GPUs are registered?

adev is placed in local_accels[0] before the loop, so n_local_accels stays
within mgpu_info.num_gpu only when one of the entries in mgpu_info.gpu_ins[]
is adev itself and gets skipped by peer_adev == adev.  During GPU reset,
amdgpu_device_halt_activities() calls amdgpu_unregister_gpu_instance(adev),
and soc_v1_0_mode2_restore_ip() resumes the IH ring before
soc_v1_0_mode2_restore_hwcontext() re-registers adev (or leaves it
unregistered if a later restore step fails).  If __check_local_vpod_integrity()
runs while adev is absent from mgpu_info.gpu_ins[] and mgpu_info.num_gpu is
AMDGPU_UALINK_LOCAL_ACCELS_MAX, the loop does not skip adev and can append
all AMDGPU_UALINK_LOCAL_ACCELS_MAX peers after local_accels[0], writing one
entry past the end of local_accels[] and peer_info->local_accels[].

Conversely, mgpu_info.num_gpu counts all registered amdgpu devices on the
host, including non-UALink GPUs (!peer_adev->ualink.info) and GPUs in other
vPods, so checking mgpu_info.num_gpu rejects a valid vPod of up to
AMDGPU_UALINK_LOCAL_ACCELS_MAX accelerators whenever another AMD GPU is
present.  Checking n_local_accels >= AMDGPU_UALINK_LOCAL_ACCELS_MAX before
appending each matching vPod peer in the loop would avoid both issues.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/tencent_B6D678900EAF7134FB708499EF1A13E93608@qq.com?part=1

      reply	other threads:[~2026-12-01  8:39 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-30 14:14 [PATCH] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check Lin Huiyi
2026-12-01  4:22 ` Lazar, Lijo
2026-12-01  4:30   ` Lazar, Lijo
2026-12-01  5:02 ` [PATCH v2] " Lin Huiyi
2026-12-01  5:44   ` Lazar, Lijo
2026-12-01  5:46     ` Lazar, Lijo
2026-12-01  5:52   ` [PATCH v3] " Lin Huiyi
2026-12-01  6:06     ` sashiko-bot
2026-12-01  6:17     ` [PATCH v4] " Lin Huiyi
2026-12-01  7:57       ` Lazar, Lijo
2026-12-01  8:21       ` [PATCH v5] " Lin Huiyi
2026-12-01  8:39         ` sashiko-bot [this message]

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=sashiko-outbox-242865@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=amd-gfx@lists.freedesktop.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=xinghui79@qq.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.