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: drm/gem: Fix inconsistent plane dimension calculation in drm_gem_fb_init_with_funcs()
Date: Sun, 12 Apr 2026 10:54:06 +1000	[thread overview]
Message-ID: <review-patch1-20260409164156.2235189-1-ashutoshdesai993@gmail.com> (raw)
In-Reply-To: <20260409164156.2235189-1-ashutoshdesai993@gmail.com>

Patch Review

**Code correctness: Good.** The change from:
```c
unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
```
to:
```c
unsigned int width = drm_format_info_plane_width(info, mode_cmd->width, i);
unsigned int height = drm_format_info_plane_height(info, mode_cmd->height, i);
```

is correct. Looking at the helper definitions in `include/drm/drm_fourcc.h:272-305`, for `plane == 0` they return the original value (matching the old `(i ? ... : 1)` logic), and for `plane > 0` they use `DIV_ROUND_UP()` instead of truncating division. This matches what `framebuffer_check()` does at `drm_framebuffer.c:172-173`.

**Bug analysis is accurate.** The concrete scenario described — NV12 (vsub=2), height=1 — is a valid reproduction case:
- `framebuffer_check()` computes chroma height = `DIV_ROUND_UP(1, 2) = 1`, passes validation
- Old `drm_gem_fb_init_with_funcs()` computes chroma height = `1 / 2 = 0`
- `min_size = (0 - 1) * pitches[i] + ...` wraps `(unsigned int)(0 - 1)` = `0xFFFFFFFF`
- The multiply + add overflows `unsigned int`, potentially yielding a small `min_size`
- A too-small GEM object passes the size guard

**Issues to address:**

1. **Missing `Fixes:` tag.** This is a bug fix and should include a `Fixes:` tag referencing the commit that introduced this code (likely the original `drm_gem_fb_init_with_funcs()` or a refactor that introduced the open-coded division). This is important for backporting decisions.

2. **Missing `Cc: stable@vger.kernel.org`.** Given this is a potential out-of-bounds access triggered from userspace (via the `DRM_IOCTL_MODE_ADDFB2` path), this should be tagged for stable backports.

3. **Minor type mismatch.** `drm_format_info_plane_width()` and `drm_format_info_plane_height()` return `int`, but the local variables are `unsigned int`. This is a pre-existing pattern (the same implicit conversion happens at `drm_framebuffer.c:172-173`), so it's not introduced by this patch — but worth noting. The values will always be positive in practice since `framebuffer_check()` rejects `width==0` and `height==0` before this code runs.

4. **Commit message quality.** The commit message is well written and clearly explains the root cause, the concrete failure scenario, and the fix. No issues here.

**Summary:** The code change is correct, minimal, and addresses a real bug that could allow a malicious userspace to bypass the GEM object size check for sub-sampled formats. It should be resubmitted with `Fixes:` and `Cc: stable` tags added.

---
Generated by Claude Code Patch Reviewer

      parent reply	other threads:[~2026-04-12  0:54 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-04-09 16:41 [PATCH] drm/gem: Fix inconsistent plane dimension calculation in drm_gem_fb_init_with_funcs() Ashutosh Desai
2026-04-10  8:26 ` Jani Nikula
2026-04-10 22:06   ` ashutosh desai
2026-04-10 22:10 ` Ashutosh Desai
2026-04-12  0:54 ` Claude review: " Claude Code Review Bot
2026-04-12  0:54 ` 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-20260409164156.2235189-1-ashutoshdesai993@gmail.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