public inbox for drm-ai-reviews@public-inbox.freedesktop.org
 help / color / mirror / Atom feed
From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: accel/rocket: fix UAF via dangling GEM handle in create_bo
Date: Mon, 25 May 2026 19:45:17 +1000	[thread overview]
Message-ID: <review-patch1-20260521165720.2113571-1-tomeu@tomeuvizoso.net> (raw)
In-Reply-To: <20260521165720.2113571-1-tomeu@tomeuvizoso.net>

Patch Review

**Bug analysis is correct.** In the original code, `drm_gem_handle_create()` was called early, exposing the handle to userspace. After `drm_gem_object_put()` drops the creation reference, the handle's reference is the sole reference. If a subsequent operation (`drm_gem_shmem_get_pages_sgt`, `drm_mm_insert_node_generic`, `iommu_map_sgtable`) fails, the `err:` label calls `drm_gem_shmem_object_free()` which kfree's the object without removing the handle from the file's IDR — classic dangling-pointer UAF.

**The fix is correct.** Moving `drm_gem_handle_create()` to line 112 (after all fallible operations) ensures the handle is never exposed to userspace if any setup step fails:

```c
	ret = drm_gem_handle_create(file, gem_obj, &args->handle);
	if (ret)
		goto err_unmap;

	drm_gem_object_put(gem_obj);

	return 0;
```

**The new error label cascade is correct** — reverse-order cleanup:

```c
err_unmap:
	iommu_unmap(rocket_priv->domain->domain,
		    rkt_obj->mm.start, rkt_obj->size);

err_remove_node:
	mutex_lock(&rocket_priv->mm_lock);
	drm_mm_remove_node(&rkt_obj->mm);
	mutex_unlock(&rocket_priv->mm_lock);

err:
	drm_gem_shmem_object_free(gem_obj);
```

`err_unmap` correctly uses `rkt_obj->size` which was updated to the actual mapped size from `iommu_map_sgtable()` at line 108 (`rkt_obj->size = ret`), so the unmap size matches what was mapped.

**The missing `drm_mm_insert_node_generic()` error check is a real bug.** Previously the return value was silently overwritten by `iommu_map_sgtable()` on the next line. If the insert failed, `rkt_obj->mm` would be uninitialized and the subsequent `iommu_map_sgtable()` would use `rkt_obj->mm.start` as a garbage address. Adding the check is important:

```c
	mutex_unlock(&rocket_priv->mm_lock);
	if (ret)
		goto err;
```

**One issue — pre-existing IOMMU domain reference leak (not introduced by this patch):**

At line 78, `rocket_iommu_domain_get()` acquires a reference on the domain:

```c
	rkt_obj->domain = rocket_iommu_domain_get(rocket_priv);
```

But all error paths reach `err:` which calls `drm_gem_shmem_object_free(gem_obj)`. This function calls `drm_gem_shmem_free()` directly — it does **not** invoke the object's `funcs->free` callback (`rocket_gem_bo_free`). So the matching `rocket_iommu_domain_put()` that lives in `rocket_gem_bo_free()` is never called on any error path. This leaks the domain reference on every failed `create_bo` call.

The fix would be to add `rocket_iommu_domain_put(rkt_obj->domain)` to the `err:` label before calling `drm_gem_shmem_object_free()`, or alternatively use `drm_gem_object_put()` in the error path (which would go through `rocket_gem_bo_free` — though that path unconditionally calls `iommu_unmap` and `drm_mm_remove_node`, which would be problematic if those operations hadn't succeeded yet).

The cleanest approach would be to add an intermediate error label:

```c
err:
	rocket_iommu_domain_put(rkt_obj->domain);
	drm_gem_shmem_object_free(gem_obj);
```

This is a pre-existing bug, not introduced by this patch, but since the author is already reworking the error paths in this function, it would be good to fix it in the same series.

**Summary:** The patch correctly fixes the UAF and the missing error check. The error path structure is sound. Recommend accepting as-is with a follow-up to address the IOMMU domain reference leak.

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-05-25  9:45 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-21 16:57 [PATCH] accel/rocket: fix UAF via dangling GEM handle in create_bo Tomeu Vizoso
2026-05-25  9:45 ` Claude Code Review Bot [this message]
2026-05-25  9:45 ` Claude review: " Claude Code Review Bot

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=review-patch1-20260521165720.2113571-1-tomeu@tomeuvizoso.net \
    --to=claude-review@example.com \
    --cc=dri-devel-reviews@example.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox