On 2025-10-17 04:42, Zhu Lingshan wrote:
Set_debug_trap ioctl should work on a specific kfd_process
even when multiple contexts feature is implemented.
For consistency, this commit allow set_debug_trap ioctl only work on the
primary kfd process of a user space program
Signed-off-by: Zhu Lingshan <[email protected]>
---
drivers/gpu/drm/amd/amdkfd/kfd_chardev.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
index 73de2de8be0f..7c02e8473622 100644
--- a/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
+++ b/drivers/gpu/drm/amd/amdkfd/kfd_chardev.c
@@ -2964,6 +2964,12 @@ static int kfd_ioctl_set_debug_trap(struct file *filep,
struct kfd_process *p, v
target = kfd_lookup_process_by_pid(pid);
}
+ if (target->context_id != KFD_CONTEXT_ID_PRIMARY) {
+ pr_debug("Set debug trap ioctl not supported on non-primary kfd
process\n");
+ r = -EOPNOTSUPP;
+ goto out;
+ }
+
This check should be after the IS_ERR_OR_NULL(target) check below.
Otherwise you dereference a bogus pointer.
We should also check that the process calling the ioctl is a primary
context (p->context_id == KFD_CONTEXT_ID_PRIMARY). You don't want to
allow a guest process (using a secondary context) to debug another
process running on the host, using any ptrace the privileges of the QEMU
host process.
Regards,
Felix
if (IS_ERR_OR_NULL(target)) {
pr_debug("Cannot find process PID %i to debug\n", args->pid);
r = target ? PTR_ERR(target) : -ESRCH;