Skip to contentSkip to conversation

drm/amdgpu: reject UALink peers outside the vPod active set

PATCH New Mukul Joshi 2 participants 2 messages Dec 4

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 drm/amdgpu: reject UALink peers outside the vPod active set

remote->peer[] is only set up for active vPod members other than this GPU, but the import ioctl and HELLO processing only range-check the accelerator id. An unused id makes connection setup run on a zeroed
peer: an uninitialized mutex and scheduler entity, and GPU address 0.

Reject such ids in the import ioctl, connection setup and HELLO processing.

Fixes 8c583a03f24c ("drm/amdgpu: Implement UALink handle import ioctl")
Fixes aa574f2570d6 ("drm/amdgpu: Resync UALink ring wptr after reboot")

---
v1->v2:
- Add the Fixes tag.

 drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c | 33 ++++++++++++++++++++++
 1 file changed, 33 insertions(+)
drivers/gpu/drm/amd/amdgpu/amdgpu_ualink.c +33 -0
index 0ce5faccfda7..6dcaf297a496 100644
@@ -58,6 +58,8 @@ static void amdgpu_ualink_reset_peer_rings(struct amdgpu_device *adev,
 					   u32 remote_accel_id);
 static int amdgpu_ualink_ring_resync_ptrs(struct amdgpu_device *adev,
 					  u32 remote_accel_id);
+static bool amdgpu_ualink_peer_is_set_up(struct amdgpu_device *adev,
+					 u32 accel_id);
 
 #define STRIP_NPA(addr)						\
 	(((u64)(addr) & ~AMDGPU_UALINK_NPA_ADDR_GPUID_MASK))
@@ -2280,6 +2282,13 @@ static void amdgpu_ualink_process_hello_msg(struct amdgpu_device *adev,
 		return;
 	}
 
+	if (!amdgpu_ualink_peer_is_set_up(adev, sender_acc_id)) {
+		dev_err_ratelimited(adev->dev,
+			"HELLO: sender AccId:%u is not in the vPod\n",
+			sender_acc_id);
+		return;
+	}
+
 	conn_state = &adev->ualink.conn_state[sender_acc_id];
 
 	/* Check if connection is already established. If yes, then receiving HELLO msg
@@ -2353,6 +2362,9 @@ static int amdgpu_ualink_setup_connection(struct amdgpu_device *adev,
 	struct amdgpu_ualink_connection *conn_state;
 	int r;
 
+	if (!amdgpu_ualink_peer_is_set_up(adev, remote_acc_id))
+		return -EINVAL;
+
 	conn_state = &adev->ualink.conn_state[remote_acc_id];
 
 	/* Connection state management goes through different states.
@@ -3899,6 +3911,13 @@ int amdgpu_ualink_import_handle(struct drm_device *dev,
 		return amdgpu_ualink_local_import(adev, remote_acc_id,
 						  &handle, fd_out);
 
+	if (!amdgpu_ualink_peer_is_set_up(adev, remote_acc_id)) {
+		dev_dbg(adev->dev,
+			"IMPORT: remote AccId:%u is not in the vPod\n",
+			remote_acc_id);
+		return -EINVAL;
+	}
+
 	xa_lock(&adev->ualink.imp_xa);
 	imp_xa_node = xa_load(&adev->ualink.imp_xa, handle.handle_lo);
 
@@ -4506,6 +4525,20 @@ static inline enum amdgpu_ualink_addr_mode ualink_addr_mode(struct amdgpu_device
 	return adev->ualink.info->vpod.addr_mode;
 }
 
+/*
+ * remote->peer[] (lock, scheduler entity, ring addresses and sizes) is only
+ * set up for members of the activation-time snapshot, excluding this GPU.
+ */
+static bool amdgpu_ualink_peer_is_set_up(struct amdgpu_device *adev,
+					 u32 accel_id)
+{
+	struct amdgpu_ualink_remote *remote = to_remote(adev);
+
+	return remote && accel_id < AMDGPU_UALINK_ACCEL_MAX &&
+	       accel_id != ualink_accel_id(adev) &&
+	       test_bit(accel_id, remote->active_accel_bits);
+}
+
 /*
  * address mode and NPA address for ring wptr, rptr, wb status, wb data
  *
Signature · 1 line
2.56.0
#1 lore raw
Thank you for your contribution! Sashiko AI review found 1 potential issue to consider: - [Low] drm/amdgpu: Fixes trailers cite non-ancestor SHAs and omit 2b4c5569d888 --

Thank you for your contribution! Sashiko AI review found 1 potential issue to consider:
- [Low] drm/amdgpu: Fixes trailers cite non-ancestor SHAs and omit 2b4c5569d888
--

commit b5c8acd96109737ef58dfc89d5be3e7a729e1358
Author: Mukul Joshi <[email protected]>

Quoted 7 lines

drm/amdgpu: reject UALink peers outside the vPod active set

remote->peer[] is only set up for active vPod members other than this GPU, but the import ioctl and HELLO processing only range-check the accelerator id. An unused id makes connection setup run on a zeroed
peer: an uninitialized mutex and scheduler entity, and GPU address 0.

Quoted 6 lines

Reject such ids in the import ioctl, connection setup and HELLO processing.

Fixes 8c583a03f24c ("drm/amdgpu: Implement UALink handle import ioctl")
Fixes aa574f2570d6 ("drm/amdgpu: Resync UALink ring wptr after reboot")

[Severity: Low]
The two Fixes tags cite commits 8c583a03f24c ("drm/amdgpu: Implement UALink handle import ioctl") and aa574f2570d6 ("drm/amdgpu: Resync UALink ring wptr after reboot"), which are not in this tree's ancestry.

In addition, 2b4c5569d888 ("drm/amdgpu: Add connection state management") originally introduced the unvalidated peer access in amdgpu_ualink_process_hello_msg() and amdgpu_ualink_setup_connection().

Should the trailers be updated to the merged commits in tree history:

Fixes 2b4c5569d888 ("drm/amdgpu: Add connection state management")
Fixes a9a7035e2ec9 ("drm/amdgpu: Implement UALink handle import ioctl")
Fixes 61c057105de5 ("drm/amdgpu: Resync UALink ring wptr after reboot")
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1