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: fbdev: omap2: fix use-after-free in omapfb_mmap
Date: Thu, 04 Jun 2026 13:04:18 +1000	[thread overview]
Message-ID: <review-patch1-20260602085421.194325-1-zenghongling@kylinos.cn> (raw)
In-Reply-To: <20260602085421.194325-1-zenghongling@kylinos.cn>

Patch Review

**Race fix on `start` (correct):**

The replacement of `omapfb_get_region_paddr(ofbi)` with inline reads from `rg` is correct. The original helper reads from `ofbi->region->...` which can be concurrently reassigned, while the patched code reads from `rg`, which was captured under the region lock:

```c
+	if (ofbi->rotation_type == OMAP_DSS_ROT_VRFB)
+		start = rg->vrfb.paddr[0];
+	else
+		start = rg->paddr;
```

This correctly ensures the physical address comes from the same region whose `map_count` will be incremented.

**Critical bug: Double `map_count` increment on success path.**

The patched code (lines 1116 and 1123 of the result file) increments `map_count` **twice** on the success path:

```c
	atomic_inc(&rg->map_count);          // line 1116: NEW increment

	r = vm_iomap_memory(vma, start, len);
	if (r)
		goto error;

	/* vm_ops.open won't be called for mmap itself. */
	atomic_inc(&rg->map_count);          // line 1123: ORIGINAL increment (kept!)
```

But `mmap_user_close()` only decrements once:

```c
static void mmap_user_close(struct vm_area_struct *vma)
{
	struct omapfb2_mem_region *rg = vma->vm_private_data;
	omapfb_get_mem_region(rg);
	atomic_dec(&rg->map_count);
	omapfb_put_mem_region(rg);
}
```

This means every successful mmap leaks +1 on `map_count`. The region will never reach map_count == 0, so it will **never be freed**. This is a memory leak that replaces the use-after-free with a resource leak.

The fix should **move** the increment (removing the original), not **add** a second one. The original `atomic_inc` after `vm_iomap_memory` should be deleted.

**Race on `len` not addressed:**

The commit message states: *"The fix is to read all required values (start, len) from the same region reference (rg)"* — but the code still reads:

```c
	len = fix->smem_len;
```

`fix->smem_len` is updated by `omapfb_setup_overlay()` at line 620 (`fix->smem_len = rg->size`), which runs under `lock` but not `mm_lock`. The v2 changelog explains this is intentional for VRFB sparse mappings, where `fix->smem_len` encompasses the VRFB address space and differs from `rg->size`. This is an acceptable compromise, but the commit message should be updated to not claim `len` is read from `rg`, since it isn't.

**Error path (correct):**

The new error path correctly undoes the pre-mapping increment:

```c
error:
+	atomic_dec(&rg->map_count);
	omapfb_put_mem_region(rg);
```

This is balanced — if `vm_iomap_memory` fails, the increment is reverted before returning. (This is only correct once the double-increment on the success path is fixed.)

**Summary of required changes:**

1. Remove the **original** `atomic_inc(&rg->map_count)` after `vm_iomap_memory()` (currently at line 1123), keeping only the new one before it. The comment `/* vm_ops.open won't be called for mmap itself. */` should be moved to above the pre-mapping increment to preserve the documentation of why it's needed.
2. Update the commit message to accurately state that `len` is still read from `fix->smem_len` (intentionally, for VRFB compatibility).

---
Generated by Claude Code Patch Reviewer

  reply	other threads:[~2026-06-04  3:04 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-06-02  8:54 [PATCH v2] fbdev: omap2: fix use-after-free in omapfb_mmap Hongling Zeng
2026-06-04  3:04 ` Claude Code Review Bot [this message]
2026-06-04  3:04 ` Claude review: " Claude Code Review Bot
  -- strict thread matches above, loose matches on Subject: below --
2026-06-02  8:04 [PATCH] " Hongling Zeng
2026-06-04  3:05 ` Claude review: " Claude Code Review Bot
2026-06-04  3:05 ` 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-20260602085421.194325-1-zenghongling@kylinos.cn \
    --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