From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: drm/msm: Add PERFCNTR_CONFIG ioctl
Date: Sat, 16 May 2026 15:20:25 +1000 [thread overview]
Message-ID: <review-patch13-20260511130017.96867-14-robin.clark@oss.qualcomm.com> (raw)
In-Reply-To: <20260511130017.96867-14-robin.clark@oss.qualcomm.com>
Patch Review
This is the core ioctl patch. Several issues:
**(1) CRITICAL: Stack buffer overflow via `group_stride`.**
```c
struct drm_msm_perfcntr_group g = {0}; // 32 bytes on stack
...
if (copy_from_user(&g, userptr, args->group_stride))
```
`args->group_stride` is only validated to be non-zero. If userspace passes `group_stride = 256`, this writes 256 bytes into a 32-byte stack variable. Similarly, the `copy_to_user` in the `MSM_PERFCNTR_UPDATE` path would leak stack contents to userspace.
Fix: cap the copy size, e.g.:
```c
size_t copy_sz = min_t(size_t, args->group_stride,
sizeof(struct drm_msm_perfcntr_group));
if (copy_from_user(&g, userptr, copy_sz))
```
**(2) Undefined behavior in `1 << bufsz_shift`.**
```c
stream->fifo_size = 1 << args->bufsz_shift;
```
`1` is `int` (32-bit). If `bufsz_shift >= 31`, this is signed integer overflow (UB). And `fifo_size` is `size_t`, so the assignment would also be wrong on 64-bit. Later:
```c
void *buf __free(kfree) =
kmalloc(1 << args->bufsz_shift, GFP_KERNEL);
```
Same UB repeated. Fix: use `1UL << args->bufsz_shift` and validate `bufsz_shift` early (e.g., `bufsz_shift > 27` returns EINVAL, consistent with the 128M limit).
**(3) Wrong variable in error message:**
```c
if (stream->fifo_size > SZ_128M)
return UERR(EINVAL, dev, "buffer size too big (>128M): %zu", bufsz);
```
Should print `stream->fifo_size`, not `bufsz` (which holds the per-period size at that point).
**(4) Error path leaks allocated counters.** If the ioctl returns an error after writing to `perfcntrs->groups[idx]->allocated_counters` (which happens in the loop at line 7432), those counters remain "allocated" even though no stream was created. The error paths before `if (ret) return ret;` should reset `allocated_counters` to 0 for all groups.
**(5) UAPI note:** The ioctl is `DRM_IOW` (write-only from user to kernel). The comment in the UAPI header explains this is intentional since the fd is returned via ioctl return value. This is correct and well-documented.
**(6) Missing `min_t` for group_stride validation would also fix forward compatibility.** If a future kernel adds fields to `drm_msm_perfcntr_group`, old userspace with a smaller struct would work correctly with `min()`. Conversely, new userspace with a bigger struct against this kernel would silently lose extra fields. This is the standard extensible-struct pattern.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-05-16 5:20 UTC|newest]
Thread overview: 46+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-11 12:59 [PATCH v5 00/16] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-05-11 12:59 ` [PATCH v5 01/16] drm/msm: Remove obsolete perf infrastructure Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 02/16] drm/msm: Allow CAP_PERFMON for setting SYSPROF Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 03/16] drm/msm/adreno: Sync registers from mesa Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 04/16] drm/msm/registers: Sync gen_header.py " Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 05/16] drm/msm/registers: Add perfcntr json Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 06/16] drm/msm: Add a6xx+ perfcntr tables Rob Clark
2026-05-13 18:55 ` Dmitry Baryshkov
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 07/16] drm/msm: Add sysprof accessors Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 08/16] drm/msm/a6xx: Add yield & flush helper Rob Clark
2026-05-13 18:56 ` Dmitry Baryshkov
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 09/16] drm/msm: Add per-context perfcntr state Rob Clark
2026-05-13 18:57 ` Dmitry Baryshkov
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 10/16] drm/msm: Add basic perfcntr infrastructure Rob Clark
2026-05-13 21:12 ` Anna Maniscalco
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 11/16] drm/msm/a6xx+: Add support to configure perfcntrs Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 12/16] drm/msm/a8xx: Add perfcntr flush sequence Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 13/16] drm/msm: Add PERFCNTR_CONFIG ioctl Rob Clark
2026-05-16 5:20 ` Claude Code Review Bot [this message]
2026-05-11 12:59 ` [PATCH v5 14/16] drm/msm/a6xx: Increase pwrup_reglist size Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 15/16] drm/msm/a6xx: Append SEL regs to dyn pwrup reglist Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-11 12:59 ` [PATCH v5 16/16] drm/msm/a6xx: Allow IFPC with perfcntr stream Rob Clark
2026-05-16 5:20 ` Claude review: " Claude Code Review Bot
2026-05-16 5:20 ` Claude review: drm/msm: Add PERFCNTR_CONFIG ioctl Claude Code Review Bot
-- strict thread matches above, loose matches on Subject: below --
2026-05-14 13:39 [PATCH v6 00/16] " Rob Clark
2026-05-14 13:40 ` [PATCH v6 13/16] " Rob Clark
2026-05-16 0:50 ` Claude review: " Claude Code Review Bot
2026-05-16 0:50 ` Claude Code Review Bot
2026-05-06 17:10 [PATCH v3 00/16] " Rob Clark
2026-05-06 17:10 ` [PATCH v4 13/16] " Rob Clark
2026-05-07 3:19 ` Claude review: " Claude Code Review Bot
2026-05-07 3:19 ` Claude Code Review Bot
2026-05-04 19:06 [PATCH v3 00/16] " Rob Clark
2026-05-04 19:06 ` [PATCH v3 13/16] " Rob Clark
2026-05-04 22:06 ` Claude review: " Claude Code Review Bot
2026-05-04 22:06 ` Claude Code Review Bot
2026-04-20 22:25 [PATCH 00/13] " Rob Clark
2026-04-20 22:25 ` [PATCH 13/13] " Rob Clark
2026-04-22 23:13 ` Claude review: " Claude Code Review Bot
2026-04-22 23:13 ` 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-patch13-20260511130017.96867-14-robin.clark@oss.qualcomm.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