From: Mario Limonciello <superm1@kernel.org>
To: Lizhi Hou <lizhi.hou@amd.com>,
ogabbay@kernel.org, quic_jhugo@quicinc.com,
dri-devel@lists.freedesktop.org,
maciej.falkowski@linux.intel.com
Cc: linux-kernel@vger.kernel.org, max.zhen@amd.com, sonal.santan@amd.com
Subject: Re: [PATCH V1] accel/amdxdna: Fix out-of-bounds memset in command slot handling
Date: Tue, 17 Feb 2026 12:55:54 -0600 [thread overview]
Message-ID: <fefd7aaf-b2af-437d-9b51-f70d1b355a63@kernel.org> (raw)
In-Reply-To: <20260217185415.1781908-1-lizhi.hou@amd.com>
On 2/17/26 12:54 PM, Lizhi Hou wrote:
> The remaining space in a command slot may be smaller than the size of
> the command header. Clearing the command header with memset() before
> verifying the available slot space can result in an out-of-bounds write
> and memory corruption.
>
> Fix this by moving the memset() call after the size validation.
>
> Fixes: 3d32eb7a5ecf ("accel/amdxdna: Fix cu_idx being cleared by memset() during command setup")
> Signed-off-by: Lizhi Hou <lizhi.hou@amd.com>
Reviewed-by: Mario Limonciello (AMD) <superm1@kernel.org>
> ---
> drivers/accel/amdxdna/aie2_message.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/accel/amdxdna/aie2_message.c b/drivers/accel/amdxdna/aie2_message.c
> index 7d7dcfeaf794..8fbbc3280468 100644
> --- a/drivers/accel/amdxdna/aie2_message.c
> +++ b/drivers/accel/amdxdna/aie2_message.c
> @@ -694,11 +694,11 @@ aie2_cmdlist_fill_npu_cf(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t *siz
> u32 cmd_len;
> void *cmd;
>
> - 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);
> if (npu_slot->cu_idx == INVALID_CU_IDX)
> return -EINVAL;
> @@ -719,7 +719,6 @@ aie2_cmdlist_fill_npu_dpu(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t *si
> u32 cmd_len;
> u32 arg_sz;
>
> - memset(npu_slot, 0, sizeof(*npu_slot));
> sn = amdxdna_cmd_get_payload(cmd_bo, &cmd_len);
> arg_sz = cmd_len - sizeof(*sn);
> if (cmd_len < sizeof(*sn) || arg_sz > MAX_NPU_ARGS_SIZE)
> @@ -728,6 +727,7 @@ aie2_cmdlist_fill_npu_dpu(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t *si
> if (*size < sizeof(*npu_slot) + arg_sz)
> return -EINVAL;
>
> + memset(npu_slot, 0, sizeof(*npu_slot));
> npu_slot->cu_idx = amdxdna_cmd_get_cu_idx(cmd_bo);
> if (npu_slot->cu_idx == INVALID_CU_IDX)
> return -EINVAL;
> @@ -751,7 +751,6 @@ aie2_cmdlist_fill_npu_preempt(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t
> u32 cmd_len;
> u32 arg_sz;
>
> - memset(npu_slot, 0, sizeof(*npu_slot));
> pd = amdxdna_cmd_get_payload(cmd_bo, &cmd_len);
> arg_sz = cmd_len - sizeof(*pd);
> if (cmd_len < sizeof(*pd) || arg_sz > MAX_NPU_ARGS_SIZE)
> @@ -760,6 +759,7 @@ aie2_cmdlist_fill_npu_preempt(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t
> if (*size < sizeof(*npu_slot) + arg_sz)
> return -EINVAL;
>
> + memset(npu_slot, 0, sizeof(*npu_slot));
> npu_slot->cu_idx = amdxdna_cmd_get_cu_idx(cmd_bo);
> if (npu_slot->cu_idx == INVALID_CU_IDX)
> return -EINVAL;
> @@ -787,7 +787,6 @@ aie2_cmdlist_fill_npu_elf(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t *si
> u32 cmd_len;
> u32 arg_sz;
>
> - memset(npu_slot, 0, sizeof(*npu_slot));
> pd = amdxdna_cmd_get_payload(cmd_bo, &cmd_len);
> arg_sz = cmd_len - sizeof(*pd);
> if (cmd_len < sizeof(*pd) || arg_sz > MAX_NPU_ARGS_SIZE)
> @@ -796,6 +795,7 @@ aie2_cmdlist_fill_npu_elf(struct amdxdna_gem_obj *cmd_bo, void *slot, size_t *si
> if (*size < sizeof(*npu_slot) + arg_sz)
> return -EINVAL;
>
> + memset(npu_slot, 0, sizeof(*npu_slot));
> npu_slot->type = EXEC_NPU_TYPE_ELF;
> npu_slot->inst_buf_addr = pd->inst_buf;
> npu_slot->save_buf_addr = pd->save_buf;
next prev parent reply other threads:[~2026-02-17 18:55 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 [this message]
2026-02-17 20:45 ` Claude review: " Claude Code Review Bot
2026-02-17 20:45 ` 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=fefd7aaf-b2af-437d-9b51-f70d1b355a63@kernel.org \
--to=superm1@kernel.org \
--cc=dri-devel@lists.freedesktop.org \
--cc=linux-kernel@vger.kernel.org \
--cc=lizhi.hou@amd.com \
--cc=maciej.falkowski@linux.intel.com \
--cc=max.zhen@amd.com \
--cc=ogabbay@kernel.org \
--cc=quic_jhugo@quicinc.com \
--cc=sonal.santan@amd.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