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: mm/zone_device: Do not touch device folio after calling ->folio_free()
Date: Sun, 12 Apr 2026 09:15:49 +1000	[thread overview]
Message-ID: <review-patch1-20260410230346.4009855-1-matthew.brost@intel.com> (raw)
In-Reply-To: <20260410230346.4009855-1-matthew.brost@intel.com>

Patch Review

**The bug:**

In `free_zone_device_folio()`, a local variable `pgmap` is saved from `folio->pgmap` at function entry (line 418 of the current tree):

```c
struct dev_pagemap *pgmap = folio->pgmap;
```

This local is used correctly throughout the function — except at line 457, where the code dereferences `folio->pgmap` again instead of using the local:

```c
pgmap->ops->folio_free(folio);
-		percpu_ref_put_many(&folio->pgmap->ref, nr);
+		percpu_ref_put_many(&pgmap->ref, nr);
```

After `folio_free()` returns, the driver may have already reallocated the folio's backing memory with a different order, meaning `folio->pgmap` can contain garbage. The stack trace confirms this — RAX holds `0x0900000000000000`, a non-canonical address, which is what you'd expect from reading a corrupted `pgmap` pointer out of a recycled folio.

**The fix:**

The one-line change replaces `folio->pgmap->ref` with `pgmap->ref`, using the local variable that was already captured before the folio was freed. This is the obviously correct fix.

**Additional observations:**

1. **Correctness**: The fix is correct. `pgmap` is captured before any mutation of the folio, and `percpu_ref_put_many` on `pgmap->ref` is the right thing to do after the folio has been freed.

2. **Fixes tag**: The `Fixes:` tag references `d245f9b4ab80 ("mm/zone_device: support large zone device private folios")` which is the commit that introduced the `nr` variable and the `percpu_ref_put_many` call (replacing an earlier `percpu_ref_put`). This seems like a reasonable attribution — the use of `folio->pgmap` instead of the local `pgmap` was likely introduced or preserved in that commit.

3. **Scope check**: Looking at the other cases in the same `switch` statement, `MEMORY_DEVICE_PCI_P2PDMA` (line 472-476) also calls `pgmap->ops->folio_free(folio)` but does not call `percpu_ref_put_many` afterward, so it doesn't have this bug. The `MEMORY_DEVICE_GENERIC` and `MEMORY_DEVICE_FS_DAX` cases don't call `folio_free` at all.

4. **Cc list**: The patch is appropriately CC'd to mm maintainers and relevant mailing lists.

**Reviewed-by worthy**: Yes, this is a clean, minimal, correct fix for a real use-after-free. No concerns.

---
Generated by Claude Code Patch Reviewer

      parent reply	other threads:[~2026-04-11 23:15 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-10 23:03 [PATCH] mm/zone_device: Do not touch device folio after calling ->folio_free() Matthew Brost
2026-04-10 23:26 ` Matthew Brost
2026-04-11 23:15 ` Claude review: " Claude Code Review Bot
2026-04-11 23:15 ` Claude Code Review Bot [this message]

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-20260410230346.4009855-1-matthew.brost@intel.com \
    --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