accel/amdxdna: fix two NULL-deref DoS paths reachable via AMDXDNA_EXEC_CMD
cover accel/amdxdna: fix two NULL-deref DoS paths reachable via AMDXDNA_EXEC_CMD
An unprivileged process with access to an AMD NPU accel node can oops the kernel with a single AMDXDNA_EXEC_CMD ioctl. Two distinct NULL dereferences are reachable on the command-submit path, both since the driver first gained command execution:
1. cmd_handles = 0 (AMDXDNA_INVALID_BO_HANDLE) leaves job->cmd_bo NULL, dereferenced later by the DRM scheduler.
2. On an AIE4 device (no .cmd_submit op) the ioctl calls a NULL function pointer.
Both are availability-only (local DoS), no memory corruption. Found by static analysis; verified against source, not runtime-reproduced (no NPU on hand).
Doruk Tan Ozturk (2):
accel/amdxdna: reject user command submission without a command BO accel/amdxdna: reject command submission on devices without a submit
op
drivers/accel/amdxdna/amdxdna_ctx.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+)
Signature · 1 line
2.43.0
PATCH 1/2 accel/amdxdna: reject user command submission without a command BO
amdxdna_drm_submit_execbuf() passes the user-supplied command BO handle straight into amdxdna_cmd_submit() with drv_cmd == NULL. When the handle is AMDXDNA_INVALID_BO_HANDLE (0), the block that fetches job->cmd_bo is skipped, leaving it NULL, and no check rejects it on the user path (the !job->cmd_bo guard lives inside the != INVALID branch).
The job is then armed and pushed to the DRM scheduler. aie2_sched_job_run() takes the drv_cmd == NULL path and calls amdxdna_cmd_set_state(job->cmd_bo) -> amdxdna_gem_vmap(NULL) -> to_gobj(NULL)->dev, a NULL pointer dereference in the drm_sched worker. A process with access to the accel node on a system with a probed AMD NPU can trigger a kernel oops with a single AMDXDNA_EXEC_CMD ioctl (cmd_handles = 0).
Only internal driver commands (SYNC_DEBUG_BO / ATTACH_DEBUG_BO) legitimately pass AMDXDNA_INVALID_BO_HANDLE, and they always set drv_cmd. Reject the invalid handle for user submissions (drv_cmd == NULL) at the submit choke point so every user path is covered.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/accel/amdxdna/amdxdna_ctx.c | 10 ++++++++++ 1 file changed, 10 insertions(+)
drivers/accel/amdxdna/amdxdna_ctx.c +10 -0
@@ -603,6 +603,16 @@ int amdxdna_cmd_submit(struct amdxdna_client *client, ret = -EINVAL ; goto free_job; } + }else if (!drv_cmd) { +/* +* Only internal driver commands (drv_cmd != NULL) may omit a +* command BO. A user command submission with the invalid handle +* would leave job->cmd_bo NULL and later fault when the scheduler +* dereferences it in amdxdna_cmd_set_state(). +*/ +XDNA_DBG (xdna,"Command BO handle required for user submission" ); + ret = -EINVAL ; + goto free_job; } ret =amdxdna_arg_bos_lookup (client, job, arg_bo_hdls, arg_bo_cnt);
Signature · 1 line
2.43.0
[email protected]
AI reviewRe: [PATCH 1/2] accel/amdxdna: reject user command submission without a command BO
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
Pre-existing issues:
- [High] The current task's mm_struct is assigned to job->mm without taking a reference count. If the submitting process exits before the DRM scheduler asynchronously executes the job, job->mm will point to a freed mm_struct, leading to a use-after-free when the scheduler thread accesses it via mmget_not_zero(). --
--- Patch [1]: [PATCH 1/2] accel/amdxdna: reject user command submission without a command BO --- commit 66fd358bad7187572b37789ea6dae38b8738ff00
Author: Doruk Tan Ozturk <[email protected]>
accel/amdxdna: reject user command submission without a command BO
This commit adds a check in amdxdna_cmd_submit() to ensure user command submissions have a valid command BO handle. It rejects invalid handles early to prevent a NULL pointer dereference in the drm_sched worker.
Quoted 21 lines
drivers/accel/amdxdna/amdxdna_ctx.c +10
-0@@ -603,6 +603,16 @@ int amdxdna_cmd_submit(struct amdxdna_client *client, ret = -EINVAL ; goto free_job; } + }else if (!drv_cmd) { +/* +* Only internal driver commands (drv_cmd != NULL) may omit a +* command BO. A user command submission with the invalid handle +* would leave job->cmd_bo NULL and later fault when the scheduler +* dereferences it in amdxdna_cmd_set_state(). +*/ +XDNA_DBG (xdna,"Command BO handle required for user submission" ); + ret = -EINVAL ; + goto free_job; } ret =amdxdna_arg_bos_lookup (client, job, arg_bo_hdls, arg_bo_cnt);
[ ... ]
Quoted 2 lines
job->hwctx = hwctx; job->mm = current->mm;
[Severity: High]
This is a pre-existing issue, but is it possible for job->mm to become a dangling pointer if the submitting process exits before the DRM scheduler asynchronously executes the job?
The current task's mm_struct is assigned to job->mm without taking a reference via mmgrab(). If a process opens the DRM file descriptor, shares it with a child process that submits a command and then immediately exits, the parent keeping the file descriptor open prevents the file's release callback from flushing pending jobs.
When the DRM scheduler asynchronously picks up the child's job in aie2_sched_job_run(), it calls mmget_not_zero(job->mm) on the freed mm_struct:
drivers/accel/amdxdna/aie2_ctx.c:aie2_sched_job_run() {
...
if (!mmget_not_zero(job->mm))
return ERR_PTR(-ESRCH);
...
}Would it be better to pin the mm_struct when assigning it to the job to prevent a use-after-free?
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Re: [PATCH 1/2] accel/amdxdna: reject user command submission without a command BO
In reply to Doruk Tan OzturkQuoted 36 lines · Doruk Tan Ozturk
amdxdna_drm_submit_execbuf()passes the user-supplied command BO handle straight intoamdxdna_cmd_submit()withdrv_cmd== NULL. When the handle isAMDXDNA_INVALID_BO_HANDLE(0), the block that fetchesjob->cmd_bois skipped, leaving it NULL, and no check rejects it on the user path (the !job->cmd_bo guard lives inside the != INVALID branch).The job is then armed and pushed to the DRM scheduler.
aie2_sched_job_run()takes thedrv_cmd== NULL path and callsamdxdna_cmd_set_state(job->cmd_bo)->amdxdna_gem_vmap(NULL)-> to_gobj(NULL)->dev, a NULL pointer dereference in thedrm_schedworker. A process with access to the accel node on a system with a probed AMD NPU can trigger a kernel oops with a singleAMDXDNA_EXEC_CMDioctl (cmd_handles= 0).Only internal driver commands (
SYNC_DEBUG_BO/ATTACH_DEBUG_BO) legitimately passAMDXDNA_INVALID_BO_HANDLE, and they always setdrv_cmd. Reject the invalid handle for user submissions (drv_cmd== NULL) at the submit choke point so every user path is covered.Fixes aac243092b70 ("accel/amdxdna: Add command execution")Found by 0sec automated security-research tooling (https://0sec.ai).
Assisted-by 0sec:claude-opus-4-8Signed-off-by Doruk Tan Ozturk <[email protected]>--- drivers/accel/amdxdna/amdxdna_ctx.c | 10 ++++++++++ 1 file changed, 10 insertions(+)drivers/accel/amdxdna/amdxdna_ctx.c +0
-0@@ -603,6 +603,16 @@ int amdxdna_cmd_submit(struct amdxdna_client *client, ret = -EINVAL ; goto free_job; }
drivers/accel/amdxdna/amdxdna_ctx.c int amdxdna_cmd_submit(struct amdxdna_client *client, · line 615
Quoted 10 lines
drivers/accel/amdxdna/amdxdna_ctx.c +10
-0+ }else if (!drv_cmd) { +/* +* Only internal driver commands (drv_cmd != NULL) may omit a +* command BO. A user command submission with the invalid handle +* would leave job->cmd_bo NULL and later fault when the scheduler +* dereferences it in amdxdna_cmd_set_state(). +*/ +XDNA_DBG (xdna,"Command BO handle required for user submission" ); + ret = -EINVAL ; + goto free_job;
Quoted 3 lines
drivers/accel/amdxdna/amdxdna_ctx.c +0
-0} ret =amdxdna_arg_bos_lookup (client, job, arg_bo_hdls, arg_bo_cnt);
Re: [PATCH 1/2] accel/amdxdna: reject user command submission without a command BO
Applied to drm-misc-fixes
Quoted 55 lines · Lizhi Hou
Quoted 42 lines · Doruk Tan Ozturk
amdxdna_drm_submit_execbuf()passes the user-supplied command BO handle straight intoamdxdna_cmd_submit()withdrv_cmd== NULL. When the handle isAMDXDNA_INVALID_BO_HANDLE(0), the block that fetchesjob->cmd_bois skipped, leaving it NULL, and no check rejects it on the user path (the !job->cmd_bo guard lives inside the != INVALID branch).The job is then armed and pushed to the DRM scheduler.
aie2_sched_job_run()takes thedrv_cmd== NULL path and callsamdxdna_cmd_set_state(job->cmd_bo)->amdxdna_gem_vmap(NULL)-> to_gobj(NULL)->dev, a NULL pointer dereference in thedrm_schedworker. A process with access to the accel node on a system with a probed AMD NPU can trigger a kernel oops with a singleAMDXDNA_EXEC_CMDioctl (cmd_handles= 0).Only internal driver commands (
SYNC_DEBUG_BO/ATTACH_DEBUG_BO) legitimately passAMDXDNA_INVALID_BO_HANDLE, and they always setdrv_cmd. Reject the invalid handle for user submissions (drv_cmd== NULL) at the submit choke point so every user path is covered.Fixes aac243092b70 ("accel/amdxdna: Add command execution")Found by 0sec automated security-research tooling (https://0sec.ai).
Assisted-by 0sec:claude-opus-4-8Signed-off-by Doruk Tan Ozturk <[email protected]>---
drivers/accel/amdxdna/amdxdna_ctx.c| 10 ++++++++++1 file changed, 10 insertions(+)drivers/accel/amdxdna/amdxdna_ctx.c +4
-0@@ -603,6 +603,16 @@ int amdxdna_cmd_submit(struct amdxdna_client *client, ret = -EINVAL; goto free_job; } + } else if (!drv_cmd) { + /* +* Only internal driver commands (drv_cmd != NULL) may omit a +* command BO. A user command submission with the invalid handle
Quoted 8 lines
+ * would leave
job->cmd_boNULL and later fault when the scheduler
+ * dereferences it inamdxdna_cmd_set_state(). + */
+XDNA_DBG(xdna, "Command BO handle required for user submission");
+ ret =-EINVAL;
+ gotofree_job;Reviewed-by Lizhi Hou <[email protected]>Quoted 2 lines
}
ret =amdxdna_arg_bos_lookup(client, job, arg_bo_hdls, arg_bo_cnt);
PATCH 2/2 accel/amdxdna: reject command submission on devices without a submit op
In reply to Doruk Tan Ozturkamdxdna_cmd_submit() calls xdna->dev_info->ops->cmd_submit() unconditionally, but only aie2_dev_ops defines that callback. aie4_vf_ops (the AIE4 SR-IOV virtual function) does not, so a user AMDXDNA_EXEC_CMD ioctl on an AIE4 device reaches a NULL function-pointer call and oopses the kernel. AIE4 submits work through a mapped user queue and doorbell, not this ioctl path.
Reject the submission early with -EOPNOTSUPP when the device provides no cmd_submit op, so the shared EXEC ioctl is a clean no-op on such devices.
Found by 0sec automated security-research tooling (https://0sec.ai).
--- drivers/accel/amdxdna/amdxdna_ctx.c | 4 ++++ 1 file changed, 4 insertions(+)
drivers/accel/amdxdna/amdxdna_ctx.c +4 -0
@@ -590,6 +590,10 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,int ret, idx;XDNA_DBG (xdna,"Command BO hdl %d, Arg BO count %d" , cmd_bo_hdl, arg_bo_cnt); + +if (!xdna->dev_info->ops->cmd_submit) +return -EOPNOTSUPP ; + job =kzalloc_flex (*job, bos, arg_bo_cnt);if (!job)return -ENOMEM ;
Signature · 1 line
2.43.0
Re: [PATCH 2/2] accel/amdxdna: reject command submission on devices without a submit op
Quoted 24 lines · Doruk Tan Ozturk
amdxdna_cmd_submit()callsxdna->dev_info->ops->cmd_submit()unconditionally, but onlyaie2_dev_opsdefines that callback.aie4_vf_ops(the AIE4 SR-IOV virtual function) does not, so a userAMDXDNA_EXEC_CMDioctl on an AIE4 device reaches a NULL function-pointer call and oopses the kernel. AIE4 submits work through a mapped user queue and doorbell, not this ioctl path.Reject the submission early with
-EOPNOTSUPPwhen the device provides nocmd_submitop, so the shared EXEC ioctl is a clean no-op on such devices.Fixes aac243092b70 ("accel/amdxdna: Add command execution")Found by 0sec automated security-research tooling (https://0sec.ai).
Assisted-by 0sec:claude-opus-4-8Signed-off-by Doruk Tan Ozturk <[email protected]>--- drivers/accel/amdxdna/amdxdna_ctx.c | 4 ++++ 1 file changed, 4 insertions(+)drivers/accel/amdxdna/amdxdna_ctx.c +0
-0
drivers/accel/amdxdna/amdxdna_ctx.c int amdxdna_cmd_submit(struct amdxdna_client *client, · line 596
Quoted 7 lines
drivers/accel/amdxdna/amdxdna_ctx.c +4
-0@@ -590,6 +590,10 @@ int amdxdna_cmd_submit(struct amdxdna_client *client,int ret, idx;XDNA_DBG (xdna,"Command BO hdl %d, Arg BO count %d" , cmd_bo_hdl, arg_bo_cnt); + +if (!xdna->dev_info->ops->cmd_submit) +return -EOPNOTSUPP ; +
Quoted 3 lines
drivers/accel/amdxdna/amdxdna_ctx.c +0
-0job =kzalloc_flex (*job, bos, arg_bo_cnt);if (!job)return -ENOMEM ;
Re: [PATCH 2/2] accel/amdxdna: reject command submission on devices without a submit op
Applied to drm-misc-fixes
Quoted 37 lines · Lizhi Hou
Quoted 24 lines · Doruk Tan Ozturk
amdxdna_cmd_submit()callsxdna->dev_info->ops->cmd_submit()unconditionally, but onlyaie2_dev_opsdefines that callback.aie4_vf_ops(the AIE4 SR-IOV virtual function) does not, so a userAMDXDNA_EXEC_CMDioctl on an AIE4 device reaches a NULL function-pointer call and oopses the kernel. AIE4 submits work through a mapped user queue and doorbell, not this ioctl path.Reject the submission early with
-EOPNOTSUPPwhen the device provides nocmd_submitop, so the shared EXEC ioctl is a clean no-op on such devices.Fixes aac243092b70 ("accel/amdxdna: Add command execution")Found by 0sec automated security-research tooling (https://0sec.ai).
Assisted-by 0sec:claude-opus-4-8Signed-off-by Doruk Tan Ozturk <[email protected]>---
drivers/accel/amdxdna/amdxdna_ctx.c| 4 ++++1 file changed, 4 insertions(+)drivers/accel/amdxdna/amdxdna_ctx.c +0
-0drivers/accel/amdxdna/amdxdna_ctx.c int amdxdna_cmd_submit(struct amdxdna_client · line 596
Quoted 7 lines
drivers/accel/amdxdna/amdxdna_ctx.c +4
-0@@ -590,6 +590,10 @@ int amdxdna_cmd_submit(struct amdxdna_client *client, int ret, idx; XDNA_DBG(xdna, "Command BO hdl %d, Arg BO count %d", cmd_bo_hdl, arg_bo_cnt); + + if (!xdna->dev_info->ops->cmd_submit) + return -EOPNOTSUPP; +Reviewed-by Lizhi Hou <[email protected]>Quoted 3 lines
drivers/accel/amdxdna/amdxdna_ctx.c +0
-0job = kzalloc_flex(*job, bos, arg_bo_cnt); if (!job) return -ENOMEM;