drm/amdkfd: Correctly handle multi-xcc mqd size in CRIU restore
Subsystems (3)
PATCH 1/1 drm/amdkfd: Correctly handle multi-xcc mqd size in CRIU restore
kfd_criu_restore_queue validates that a CRIU restore has the correct mqd size, but doesn't correctly handle that the mqd will be scaled but the number of xccs.
Change the check to handle multiple xccs correctly.
--- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2 -1
@@ -1030,7 +1030,8 @@ int kfd_criu_restore_queue(struct kfd_process *p, goto exit; } -if (q_data->mqd_size !=mqd_size_from_queue_type (pdd->dev->dqm, q_data->type)) { +if (q_data->mqd_size !=mqd_size_from_queue_type (pdd->dev->dqm, q_data->type) * +NUM_XCC (pdd->dev->xcc_mask)) { ret = -EINVAL ; goto exit; }
Signature · 1 line
2.34.1
[email protected]
AI reviewThank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce: - [Critical] drm/amdkfd: missing bounds check in…
Thank you for your contribution! Sashiko AI review found no new issues in this patch, but noticed 1 related pre-existing issue it does not introduce:
- [Critical] drm/amdkfd: missing bounds check in kfd_criu_restore_queue() [1]
--
commit b6c60f35cb12af1932936a6a6d849d52fd98120b
Author: David Francis <[email protected]>
drm/amdkfd: Correctly handle multi-xcc mqd size in CRIU restore
This commit scales the expected mqd_size check in kfd_criu_restore_queue() by the number of XCCs on the device.
Quoted 5 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +0
-0
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c int kfd_criu_restore_queue(struct kfd_process *p, · line 1048
Quoted 9 lines
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +2
-1@@ -1041,7 +1041,8 @@ int kfd_criu_restore_queue(struct kfd_process *p, goto exit; } -if (q_data->mqd_size !=mqd_size_from_queue_type (pdd->dev->dqm, q_data->type)) { +if (q_data->mqd_size !=mqd_size_from_queue_type (pdd->dev->dqm, q_data->type) * +NUM_XCC (pdd->dev->xcc_mask)) { ret = -EINVAL ; goto exit; }
[Severity: Critical]
This problem wasn't introduced by this patch, but can an unvalidated q_data->priority cause an out-of-bounds read of pipe_priority_map[] [1]?
kfd_criu_restore_queue() checks q_data->type and q_data->mqd_size after copy_from_user(), then set_queue_properties_from_criu() copies q_data->priority into qp.priority without checking it against KFD_MAX_QUEUE_PRIORITY (15):
drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c:set_queue_properties_from_criu() {
qp->is_interop = false;
qp->queue_percent = q_data->q_percent;
qp->priority = q_data->priority;
...
}When pqm_create_queue() invokes the hardware-specific update_mqd() -> set_priority() path, qp.priority indexes directly into the 16-element pipe_priority_map[] array and writes the result into the MQD, which can crash the kernel or leak out-of-bounds kernel memory through a userspace-mapped MQD.
[1] https://sashiko.dev/#/bug/linux-ce93c1d0-79a1-4b46-89c1-185592185549
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
AMD General
Quoted 41 lines
-----Original Message-----
From: Francis, David <[email protected]>
Sent: Monday, November 23, 2026 2:26 PM
To: [email protected]
Cc: Francis, David <[email protected]>; Yat Sin, David <[email protected]>; Deucher, Alexander <[email protected]>
Subject: [PATCH] drm/amdkfd: Correctly handle multi-xcc mqd size in CRIU restore
kfd_criu_restore_queuevalidates that a CRIU restore has the correct mqd size, but doesn't correctly handle that the mqd will be scaled but the number of xccs.Change the check to handle multiple xccs correctly.
Cc David Yat Sin <[email protected]>Cc Alex Deucher <[email protected]>Fixes 47ea05f246be ("drm/amdkfd: Check bounds on CRIU restore queue type andmqd size")
Signed-off-by David Francis <[email protected]>--- drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/amdkfd/kfd_process_queue_manager.c +1
-1@@ -1030,7 +1030,8 @@ int kfd_criu_restore_queue(struct kfd_process *p, goto exit; } -if (q_data->mqd_size !=mqd_size_from_queue_type (pdd->dev->dqm, q_data->type)) { + if (q_data->mqd_size != mqd_size_from_queue_type(pdd->dev->dqm,
q_data->type) *+ NUM_XCC(pdd->dev->xcc_mask)) { ret = -EINVAL; goto exit; }--
2.34.1