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

* Re: [PATCH] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  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
  1 sibling, 1 reply; 12+ messages in thread
From: Lazar, Lijo @ 2026-12-01  4:22 UTC (permalink / raw)
  To: Lin Huiyi, alexander.deucher, christian.koenig
  Cc: airlied, simona, amd-gfx, dri-devel



On 30-Nov-26 7:44 PM, Lin Huiyi wrote:
> [Some people who received this message don't often get email from xinghui79@qq.com. Learn why this is important at https://aka.ms/LearnAboutSenderIdentification ]
> 
> __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));

This is incorrect.

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

Current max of 8 is sufficient.

Thanks,
Lijo

>   #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	[flat|nested] 12+ messages in thread

* Re: [PATCH] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  2026-12-01  4:22 ` Lazar, Lijo
@ 2026-12-01  4:30   ` Lazar, Lijo
  0 siblings, 0 replies; 12+ messages in thread
From: Lazar, Lijo @ 2026-12-01  4:30 UTC (permalink / raw)
  To: Lin Huiyi, alexander.deucher, christian.koenig
  Cc: airlied, simona, amd-gfx, dri-devel



On 01-Dec-26 9:52 AM, Lazar, Lijo wrote:
> 
> 
> On 30-Nov-26 7:44 PM, Lin Huiyi wrote:
>> [Some people who received this message don't often get email from 
>> xinghui79@qq.com. Learn why this is important at https://aka.ms/ 
>> LearnAboutSenderIdentification ]
>>
>> __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));
> 
> This is incorrect.

On a second look, this optimization is fine.

Thanks,
Lijo

> 
>>          }
>>
>>          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
> 
> Current max of 8 is sufficient.
> 
> Thanks,
> Lijo
> 
>>   #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	[flat|nested] 12+ messages in thread

* [PATCH v2] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  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  5:02 ` Lin Huiyi
  2026-12-01  5:44   ` Lazar, Lijo
  2026-12-01  5:52   ` [PATCH v3] " Lin Huiyi
  1 sibling, 2 replies; 12+ messages in thread
From: Lin Huiyi @ 2026-12-01  5:02 UTC (permalink / raw)
  To: Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, 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.

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 <xinghui79@qq.com>
---
 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;
+		}
 		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;
-- 
2.56.1


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

* Re: [PATCH v2] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  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
  1 sibling, 1 reply; 12+ messages in thread
From: Lazar, Lijo @ 2026-12-01  5:44 UTC (permalink / raw)
  To: Lin Huiyi, Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, amd-gfx, dri-devel



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 <xinghui79@qq.com>
> ---
>   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)


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;


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

* Re: [PATCH v2] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  2026-12-01  5:44   ` Lazar, Lijo
@ 2026-12-01  5:46     ` Lazar, Lijo
  0 siblings, 0 replies; 12+ messages in thread
From: Lazar, Lijo @ 2026-12-01  5:46 UTC (permalink / raw)
  To: Lin Huiyi, Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, amd-gfx, dri-devel



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 <xinghui79@qq.com>
>> ---
>>   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;
> 


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

* [PATCH v3] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  2026-12-01  5:02 ` [PATCH v2] " Lin Huiyi
  2026-12-01  5:44   ` Lazar, Lijo
@ 2026-12-01  5:52   ` Lin Huiyi
  2026-12-01  6:06     ` sashiko-bot
  2026-12-01  6:17     ` [PATCH v4] " Lin Huiyi
  1 sibling, 2 replies; 12+ messages in thread
From: Lin Huiyi @ 2026-12-01  5:52 UTC (permalink / raw)
  To: Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, 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.

Reject a pod with more local GPUs than the array can hold before the
loop starts, and only copy the entries that were filled in.

Changes since v2:
- Move the bounds check out of the loop and base it on the number of
  local GPUs, as suggested by Lijo Lazar.

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 <xinghui79@qq.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 13 ++++++++++++-
 1 file changed, 12 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..7240a57ab6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -1164,6 +1164,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)
@@ -1257,7 +1268,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;
-- 
2.56.1


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

* Re: [PATCH v3] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  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
  1 sibling, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-12-01  6:06 UTC (permalink / raw)
  To: Lin Huiyi; +Cc: amd-gfx, dri-devel

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 <xinghui79@qq.com>

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/tencent_90933440D34FACA121875E13683CE1BC3309@qq.com?part=1

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

* [PATCH v4] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  2026-12-01  5:52   ` [PATCH v3] " Lin Huiyi
  2026-12-01  6:06     ` sashiko-bot
@ 2026-12-01  6:17     ` Lin Huiyi
  2026-12-01  7:57       ` Lazar, Lijo
  2026-12-01  8:21       ` [PATCH v5] " Lin Huiyi
  1 sibling, 2 replies; 12+ messages in thread
From: Lin Huiyi @ 2026-12-01  6:17 UTC (permalink / raw)
  To: Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, 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.

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

Changes since v3:
- Move the bounds check back into the loop.  Testing mgpu_info.num_gpu
  before the loop is not equivalent: that counter includes non-UALink
  GPUs and GPUs in other vPods, so valid configurations would be
  rejected; and it misses the overflow when adev was already removed
  from mgpu_info.gpu_ins[] by amdgpu_unregister_gpu_instance() during
  reset or unload, where n_local_accels still reaches 9 with 8
  remaining peers.

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 <xinghui79@qq.com>
---
 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;
+		}
 		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;
-- 
2.56.1


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

* Re: [PATCH v4] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  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
  1 sibling, 0 replies; 12+ messages in thread
From: Lazar, Lijo @ 2026-12-01  7:57 UTC (permalink / raw)
  To: Lin Huiyi, Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, amd-gfx, dri-devel



On 01-Dec-26 11:47 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 v3:
> - Move the bounds check back into the loop.  Testing mgpu_info.num_gpu
>    before the loop is not equivalent: that counter includes non-UALink
>    GPUs and GPUs in other vPods, so valid configurations would be
>    rejected; and it misses the overflow when adev was already removed
>    from mgpu_info.gpu_ins[] by amdgpu_unregister_gpu_instance() during
>    reset or unload, where n_local_accels still reaches 9 with 8
>    remaining peers.
> 

Sashiko analysis is a theoretical possibility.

The actual intention of the code and the actual platform configuration is -

AMDGPU_UALINK_LOCAL_ACCELS_MAX represents the maximum possible local 
GPUs which are part of a physical pod (not VPOD). The number of GPUs 
that are registered in mgpu_info.num_gpu will also be restricted to the 
same number because of the way platform is configured.

Thanks,
Lijo

> 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 <xinghui79@qq.com>
> ---
>   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;
> +		}
>   		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;


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

* [PATCH v5] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  2026-12-01  6:17     ` [PATCH v4] " Lin Huiyi
  2026-12-01  7:57       ` Lazar, Lijo
@ 2026-12-01  8:21       ` Lin Huiyi
  2026-12-01  8:39         ` sashiko-bot
  1 sibling, 1 reply; 12+ messages in thread
From: Lin Huiyi @ 2026-12-01  8:21 UTC (permalink / raw)
  To: Alex Deucher, Christian König
  Cc: David Airlie, Simona Vetter, 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.

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

Changes since v4:
- Move the bounds check out of the loop and base it on the GPU count, as
  suggested by Lijo Lazar.  amdgpu_unregister_gpu_instance() removes the
  device from mgpu_info and decrements num_gpu in the same place, so
  n_local_accels cannot grow beyond num_gpu and the overflow window
  described in v4 does not exist.  Thanks to Lijo for clarifying how the
  platform configuration limits the number of registered GPUs.

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 <xinghui79@qq.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 14 +++++++++++++-
 1 file changed, 13 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..12d0a62f8e 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c
@@ -1164,6 +1164,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)
@@ -1257,7 +1269,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;
-- 
2.56.1


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

* Re: [PATCH v5] drm/amdgpu: Fix stack buffer overflow in UALink vPod integrity check
  2026-12-01  8:21       ` [PATCH v5] " Lin Huiyi
@ 2026-12-01  8:39         ` sashiko-bot
  0 siblings, 0 replies; 12+ messages in thread
From: sashiko-bot @ 2026-12-01  8:39 UTC (permalink / raw)
  To: Lin Huiyi; +Cc: amd-gfx, dri-devel

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

^ permalink raw reply	[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