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 1d7eca73ed4f664c879aa6472e418261effb5a74 Author: Lin Huiyi <[email protected]> drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check This commit adds a check on mgpu_info.num_gpu against AMDGPU_UALINK_LOCAL_ACCELS_MAX in __check_local_vpod_integrity() and limits the memcpy() length to the populated entries in local_accels[]. > diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > index fa4c3d27d2720..f697dde5a0d4d 100644 > --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c > @@ -1162,6 +1162,17 @@ 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, > + * so more GPUs than AMDGPU_UALINK_LOCAL_ACCELS_MAX 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] Should the bounds check test n_local_accels against AMDGPU_UALINK_LOCAL_ACCELS_MAX inside the loop after filtering for vPod membership, instead of checking mgpu_info.num_gpu up front? mgpu_info.num_gpu counts all registered amdgpu instances in the system, whereas the loop skips non-UALink GPUs (!peer_adev->ualink.info) and GPUs in other vPods (!test_bit(accel_id, info->vpod.active_accel_bits)). Checking mgpu_info.num_gpu > AMDGPU_UALINK_LOCAL_ACCELS_MAX before filtering rejects valid vPods of 8 or fewer GPUs on systems that also have an integrated or non-UALink GPU, or that partition more than 8 local GPUs across multiple vPods. In addition, local_accels[0] is already populated with info->ppod.accel_id before the loop (n_local_accels == 1). Allowing mgpu_info.num_gpu == 8 assumes adev itself is in mgpu_info.gpu_ins[] and will be skipped by peer_adev == adev. However, amdgpu_unregister_gpu_instance() removes adev from mgpu_info.gpu_ins[] before interrupts are disabled in amdgpu_driver_unload_kms() and during reset in amdgpu_device_halt_activities(). If __check_local_vpod_integrity() runs from amdgpu_ualink_config_update_handler() while adev is not in mgpu_info.gpu_ins[] and 8 matching peers remain, n_local_accels reaches 9 and writes one element past the end of local_accels[] and peer_info->local_accels[]. -- Sashiko AI review ยท https://sashiko.dev/#/patchset/[email protected]?part=1
