dri-devel Archive on lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
@ 2026-11-30 14:14 Lin Huiyi
  2026-12-01  4:22 ` Lazar, Lijo
  2026-12-01  5:02 ` [PATCH v2] " Lin Huiyi
  0 siblings, 2 replies; 12+ messages in thread
From: Lin Huiyi @ 2026-11-30 14:14 UTC (permalink / raw)
  To: alexander.deucher, christian.koenig
  Cc: airlied, simona, lijo.lazar, amd-gfx, dri-devel, Lin Huiyi

__check_local_vpod_integrity() collects the accelerator IDs of all local
GPUs that belong to the vPod into a fixed-size local_accels[] array. The
loop is bounded by mgpu_info.num_gpu (up to MAX_GPU_INSTANCE, i.e. 64)
and only filters peers by vPod membership, so every matching peer is
appended unconditionally:

	local_accels[n_local_accels++] = accel_id;

There is no check that n_local_accels stays below
AMDGPU_UALINK_LOCAL_ACCELS_MAX, so a pod with more local GPUs than the
array can hold writes past the end of a stack array. The oversized
count is then propagated to peer_info->n_local_accels, and the
downstream loops in amdgpu_ualink_is_local_accel() and
activate_local_vpod() walk past the end of the peer's local_accels[]
array as well.

The firmware interface allows up to PSP_GFX_MAX_LOCAL_GPUS_UAL_V1 (16)
local GPUs per node, so fix the capacity to that value and reject a pod
that reports more local peers than the array can hold.

Fixes: 0e8eb0dcea51 ("drm/amdgpu: Assign accel state based on ASP config")
Signed-off-by: Lin Huiyi <xinghui79@qq.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 8 +++++++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h | 2 +-
 2 files changed, 8 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
index d025b4183b..b4fac5ecab 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -1243,6 +1243,12 @@ static int __check_local_vpod_integrity(struct amdgpu_device *adev)
 				 accel_id);
 			return -EINVAL;
 		}
+		if (n_local_accels >= AMDGPU_UALINK_LOCAL_ACCELS_MAX) {
+			dev_warn(adev->dev,
+				 "UALINK: integrity fail: too many local vpod peers: %u (max %u)\n",
+				 n_local_accels + 1, AMDGPU_UALINK_LOCAL_ACCELS_MAX);
+			return -EINVAL;
+		}
 		local_accels[n_local_accels++] = accel_id;
 	}
 
@@ -1257,7 +1263,7 @@ static int __check_local_vpod_integrity(struct amdgpu_device *adev)
 
 		peer_info->n_local_accels = n_local_accels;
 		memcpy(peer_info->local_accels, local_accels,
-		       sizeof(local_accels));
+		       n_local_accels * sizeof(*local_accels));
 	}
 
 	return 0;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h
index 85c9a9634a..c8577a94a4 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.h
@@ -34,7 +34,7 @@ struct amdgpu_device;
 struct amdgpu_xcp;
 
 #define AMDGPU_UALINK_ACCEL_MAX 256
-#define AMDGPU_UALINK_LOCAL_ACCELS_MAX 8
+#define AMDGPU_UALINK_LOCAL_ACCELS_MAX 16
 #define AMDGPU_UALINK_STATIONS_MAX 64
 
 /* A vpod_id of 0 is reserved and treated as invalid/no vPod */
-- 
2.56.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2026-12-01  8:39 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox