From: Claude Code Review Bot <claude-review@example.com>
To: dri-devel-reviews@example.com
Subject: Claude review: accel/amdxdna: Fix out-of-bounds memset in command slot handling
Date: Wed, 18 Feb 2026 06:45:36 +1000 [thread overview]
Message-ID: <review-patch1-20260217185415.1781908-1-lizhi.hou@amd.com> (raw)
In-Reply-To: <20260217185415.1781908-1-lizhi.hou@amd.com>
Patch Review
The fix is applied consistently across all four affected functions: `aie2_cmdlist_fill_npu_cf`, `aie2_cmdlist_fill_npu_dpu`, `aie2_cmdlist_fill_npu_preempt`, and `aie2_cmdlist_fill_npu_elf`.
The pattern in each case is the same. Taking `aie2_cmdlist_fill_npu_cf` as representative:
> - memset(npu_slot, 0, sizeof(*npu_slot));
> cmd = amdxdna_cmd_get_payload(cmd_bo, &cmd_len);
> if (*size < sizeof(*npu_slot) + cmd_len)
> return -EINVAL;
>
> + memset(npu_slot, 0, sizeof(*npu_slot));
> npu_slot->cu_idx = amdxdna_cmd_get_cu_idx(cmd_bo);
The `slot` pointer comes from `cmdbuf_abo->mem.kva + offset` where the available space is `cmdbuf_abo->mem.size - offset`. When multiple commands are chained, `offset` advances with each slot, and the remaining space can become smaller than `sizeof(struct cmd_chain_slot_npu)` (which is 56+ bytes with the packed struct header fields). Writing `sizeof(*npu_slot)` bytes via memset before checking that there is room would corrupt whatever follows the buffer.
Moving the memset after the size validation is the correct fix. After the check passes, `*size >= sizeof(*npu_slot) + payload_size`, so the memset of `sizeof(*npu_slot)` bytes is guaranteed to be in bounds.
One minor observation on `aie2_cmdlist_fill_npu_elf`: unlike the other three functions, this one does not set `npu_slot->cu_idx` and instead immediately sets `npu_slot->type`. The memset still correctly appears after the size check, so the fix is consistent. This just means `cu_idx` will be left at zero from the memset, which appears intentional since ELF-type slots apparently don't need a CU index.
The commit message is accurate, the Fixes tag correctly identifies the commit that introduced the regression, and the change is minimal and correct. No issues found.
---
Generated by Claude Code Patch Reviewer
next prev parent reply other threads:[~2026-02-17 20:45 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-17 18:54 [PATCH V1] accel/amdxdna: Fix out-of-bounds memset in command slot handling Lizhi Hou
2026-02-17 18:55 ` Mario Limonciello
2026-02-17 20:45 ` Claude Code Review Bot [this message]
2026-02-17 20:45 ` Claude review: " 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-20260217185415.1781908-1-lizhi.hou@amd.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