From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: accel/ivpu: Add bounds check for firmware runtime memory
Date: Thu, 04 Jun 2026 16:34:17 +1000 [thread overview]
Message-ID: <review-patch1-20260529120853.135876-1-andrzej.kacprowski@linux.intel.com> (raw)
In-Reply-To: <20260529120853.135876-1-andrzej.kacprowski@linux.intel.com>
Patch Review
**Positive aspects:**
- The three checks are individually valid and worthwhile. Page alignment of `runtime_addr` and `runtime_size` is important since `ivpu_bo_create_runtime()` ultimately allocates pages, and an unaligned size would waste or mismap memory. The `runtime_size >= image_size` check prevents writing the firmware image beyond the allocated buffer.
- The error messages are clear and include the relevant values for debugging.
- The Fixes tag and stable backport annotation are appropriate.
**Issue 1 (medium): Check placement is too late**
The new checks are inserted *after* the existing `FW_FILE_IMAGE_OFFSET + image_size > fw->file->size` check (around current line 257-260 in drm-next), but *before* the `ivpu_is_within_range(image_load_addr, ...)` check. However, looking at the current tree, the `runtime_addr`/`runtime_size` range check already exists *earlier* at lines 251-255:
```c
if (!ivpu_is_within_range(runtime_addr, runtime_size, &vdev->hw->ranges.runtime)) {
ivpu_err(vdev, "Invalid firmware runtime address: 0x%llx and size %llu\n",
runtime_addr, runtime_size);
return -EINVAL;
}
```
The alignment and sizing checks should be placed **before** this existing `ivpu_is_within_range()` call (i.e., right after lines 245-249 where `runtime_addr`, `runtime_size`, and `image_size` are assigned), not after it. That way, obviously-invalid values (misaligned or undersized) are rejected before being fed into the range check, which provides a more logical validation ordering: basic sanity first, then range containment.
**Issue 2 (medium): Missing underflow check on `runtime_size` computation**
At line 246 of the current tree:
```c
runtime_size = fw_hdr->runtime_size - boot_params_size - fw_version_size;
```
`fw_hdr->runtime_size` is a `u32` (from `vpu_boot_api.h:75`), `boot_params_size` is `SZ_4K` (u64), and `fw_version_size` is `ALIGN(fw_hdr->firmware_version_size, SZ_4K)` (u64). Since `runtime_size` is a local `u64`, if `fw_hdr->runtime_size` is smaller than the sum of the subtractions, this will produce a large wrapping value rather than a negative number. That wrapped value would then pass the `PAGE_ALIGNED` and `runtime_size >= image_size` checks (and even the `ivpu_is_within_range` check could behave unexpectedly with a near-`U64_MAX` size).
Since this patch is already adding validation in this area, it would be worth also adding an underflow guard:
```c
if (fw_hdr->runtime_size < boot_params_size + fw_version_size) {
ivpu_err(vdev, "Runtime size too small for boot params and fw version\n");
return -EINVAL;
}
```
This should be placed before the subtraction at line 246.
**Issue 3 (minor): Format specifier correctness**
The `%llu` format specifiers are correct for the `u64` local variables `runtime_addr`, `runtime_size`, and `image_size`. No issue here.
**Issue 4 (minor/nit): The `runtime_size < image_size` check is somewhat redundant**
The later `ivpu_is_within_range(image_load_addr, image_size, &vdev->hw->ranges.runtime)` check combined with `image_load_addr == runtime_addr` (they are both assigned from `fw_hdr->image_load_address`) means the image must fit within the runtime hardware range. However, `runtime_size` as computed here is not the full hardware range — it's the header's `runtime_size` minus boot params and fw version. So the new check `runtime_size < image_size` is a valid additional constraint ensuring the image fits in the *allocated* runtime buffer, not just the hardware range. This is correct and non-redundant.
**Summary:** The patch addresses a real gap in firmware image validation. The recommended changes are: (1) move the new checks earlier, right after lines 245-249, before the existing `ivpu_is_within_range(runtime_addr, ...)` call; (2) add an underflow check on the `runtime_size` subtraction. With those fixes, this should be good to merge.
---
Generated by Claude Code Patch Reviewer
prev parent reply other threads:[~2026-06-04 6:34 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-05-29 12:08 [PATCH] accel/ivpu: Add bounds check for firmware runtime memory Andrzej Kacprowski
2026-05-29 12:27 ` Wachowski, Karol
2026-06-02 5:50 ` Wachowski, Karol
2026-06-04 6:34 ` Claude review: " Claude Code Review Bot
2026-06-04 6:34 ` 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-20260529120853.135876-1-andrzej.kacprowski@linux.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