On 01-Dec-26 11:14 AM, Lazar, Lijo wrote:


On 01-Dec-26 10:32 AM, Lin Huiyi wrote:
__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.

Reject a pod that reports more local peers than the array can hold, and
only copy the entries that were filled in.

Changes since v1:
- Keep AMDGPU_UALINK_LOCAL_ACCELS_MAX at 8 as the current limit is
   sufficient (Lijo Lazar).

Fixes: 0e8eb0dcea51 ("drm/amdgpu: Assign accel state based on ASP config")
Signed-off-by: Lin Huiyi <[email protected]>
---
  drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 8 +++++++-
  1 file changed, 7 insertions(+), 1 deletion(-)

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;
+        }

Missed this earlier. This check could be a generic one done outside the loop

unlikely (mgpu_info.num_gpu >= AMDGPU_UALINK_LOCAL_ACCELS_MAX)


Correction, error check on mgpu_info.num_gpu > AMDGPU_UALINK_LOCAL_ACCELS_MAX

For this config, we don't expect the number of GPUs detected in the system to be > maximum number of local accelerators.

Thanks,
Lijo


Thanks,
Lijo

          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;


Reply via email to