Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
Pre-existing issues: - [High] Unwinding a successfully prepared OP_MAP_SPARSE operation in nouveau_uvmm_bind_job_submit() causes a guaranteed NULL pointer dereference. - [High] Unwinding a successfully prepared OP_UNMAP_SPARSE operation leaves the region permanently dirty, causing uninterruptible hangs for future operations. -- commit 203035037bce29ea5a47c8cbbdd0cff202e6dbea Author: Peiyang He <[email protected]> Subject: drm/nouveau/uvmm: fix UAF in bind job cleanup This patch clears op->reg on the unwind_continue paths for OP_UNMAP_SPARSE. This prevents a stale region pointer from being passed to cleanup after an async sparse unmap fails, avoiding a use-after-free. > diff --git a/drivers/gpu/drm/nouveau/nouveau_uvmm.c > b/drivers/gpu/drm/nouveau/nouveau_uvmm.c > index f5e4756b4de4a..aad14316cbefd 100644 > --- a/drivers/gpu/drm/nouveau/nouveau_uvmm.c > +++ b/drivers/gpu/drm/nouveau/nouveau_uvmm.c > @@ -1318,6 +1318,7 @@ nouveau_uvmm_bind_job_submit(struct nouveau_job *job, > op->reg = nouveau_uvma_region_find(uvmm, op->va.addr, > op->va.range); > if (!op->reg || op->reg->dirty) { > + op->reg = NULL; > ret = -ENOENT; > goto unwind_continue; > } > @@ -1327,6 +1328,7 @@ nouveau_uvmm_bind_job_submit(struct nouveau_job *job, > op->va.range); > if (IS_ERR(op->ops)) { > ret = PTR_ERR(op->ops); > + op->reg = NULL; > goto unwind_continue; > } [Severity: High] This isn't a bug introduced by this patch, but looking at the unwind path triggered by goto unwind_continue, does the unwind loop cause a null pointer dereference for OP_MAP_SPARSE operations? When unwinding a successfully prepared OP_MAP_SPARSE operation, the code unconditionally calls drm_gpuva_ops_free(&uvmm->base, op->ops). However, op->ops is never allocated for OP_MAP_SPARSE and remains NULL. The drm_gpuva_ops_free() function does not check for NULL and evaluates &(ops)->list inside the drm_gpuva_for_each_op_safe() iterator: drm_gpuvm.c:drm_gpuva_ops_free() { struct drm_gpuva_op *op, *next; drm_gpuva_for_each_op_safe(op, next, ops) { list_del(&op->entry); ... Could this crash if a VM_BIND job submits an OP_MAP_SPARSE operation followed by a malformed operation that fails? [Severity: High] This is also a pre-existing issue in the same unwind path, but does unwinding a successfully prepared OP_UNMAP_SPARSE operation leave the region permanently dirty? The prepare phase for OP_UNMAP_SPARSE calls nouveau_uvma_region_dirty(op->reg). If a subsequent operation fails, the unwind loop restores the region to the maple tree and unconditionally clears op->reg = NULL without clearing the dirty flag or signaling the completion: nouveau_uvmm.c:nouveau_uvmm_bind_job_submit() unwind path { ... case OP_UNMAP_SPARSE: __nouveau_uvma_region_insert(uvmm, op->reg); nouveau_uvmm_sm_unmap_prepare_unwind(uvmm, &op->new, op->ops); break; ... drm_gpuva_ops_free(&uvmm->base, op->ops); op->ops = NULL; op->reg = NULL; ... Because op->reg is cleared here, the nouveau_uvmm_bind_job_cleanup() function skips it, meaning nouveau_uvma_region_complete(op->reg) is never called. Will future tasks attempting to map over this leaked region hang forever waiting on ®->complete in bind_validate_map_common()? -- Sashiko AI review ยท https://sashiko.dev/#/patchset/7f26d29d0bd60619+20260901063255.661503-1-peiyang...@smail.nju.edu.cn?part=1
