dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Eva Crystal" <0xiviel@gmail.com>
Cc: dri-devel@lists.freedesktop.org
Subject: Re: [PATCH v2 2/2] accel/amdxdna: bound the firmware-supplied mailbox register offsets
Date: Sun, 13 Sep 2026 21:44:50 +0000	[thread overview]
Message-ID: <20260913214451.639251F000FF@smtp.kernel.org> (raw)
In-Reply-To: <cddcbf5989cdbf6da94855152a34451ffa07860b.1789334558.git.0xiviel@gmail.com>

Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:

Pre-existing issues:
- [High] The firmware-supplied ring buffer offsets (`rb_start_addr`) and sizes (`rb_size`) are not validated against the mapped ring buffer size, leaving the driver vulnerable to out-of-bounds MMIO accesses.
- [High] Initial ring buffer head and tail pointers read from firmware are not validated against the ring buffer bounds upon channel start.
--

commit e583a0672be522b7766ae36362808346f5791f45
Author: Eva Crystal <0xiviel@gmail.com>

accel/amdxdna: bound the firmware-supplied mailbox register offsets

This patch adds bounds checking for firmware-supplied mailbox register
offsets against the device's mailbox window size. It aims to secure the 
trust boundary between the driver and firmware by preventing out-of-bounds 
kernel MMIO accesses through the mailbox mapping.

> diff --git a/drivers/accel/amdxdna/amdxdna_mailbox.c b/drivers/accel/amdxdna/amdxdna_mailbox.c
> index cc8865f4e79c9..a390836fe797c 100644
> --- a/drivers/accel/amdxdna/amdxdna_mailbox.c
> +++ b/drivers/accel/amdxdna/amdxdna_mailbox.c

[ ... ]

> @@ -518,6 +545,16 @@ xdna_mailbox_start_channel(struct mailbox_channel *mb_chann,
>  		return -EINVAL;
>  	}
>  
> +	/* A zero iohub_int_addr means the platform has no such register. */
> +	if (!mailbox_chann_res_in_range(mb_chann, x2i) ||
> +	    !mailbox_chann_res_in_range(mb_chann, i2x) ||
> +	    (iohub_int_addr && !mailbox_reg_in_range(mb_chann, iohub_int_addr))) {

[Severity: High]
This isn't a bug introduced by this patch, but while this secures the mailbox
register offsets, does it overlook the ring buffer offsets and sizes?

In xdna_mailbox_start_channel(), the firmware-supplied channel resources are
checked here, but rb_start_addr and rb_size are not validated against the
mapped ringbuf_size. This can lead to out-of-bounds writes later:

drivers/accel/amdxdna/amdxdna_mailbox.c:mailbox_send_msg() {
    ...
    write_addr = mb_chann->mb->res.ringbuf_base + start_addr + tail;
    memcpy_toio(write_addr, &mb_msg->pkg, mb_msg->pkg_size);
    ...
}

Could a compromised firmware provide maliciously large rb_start_addr or 
rb_size values, causing out-of-bounds MMIO accesses when calculating 
write_addr?


[Severity: High]
This is also a pre-existing issue, but does this function also need to
validate the initial head and tail pointers read from the firmware?

Right after the new checks in xdna_mailbox_start_channel(), the driver caches
the initial pointers directly from the firmware:

drivers/accel/amdxdna/amdxdna_mailbox.c:xdna_mailbox_start_channel() {
    ...
    mb_chann->x2i_tail = mailbox_get_tailptr(mb_chann, CHAN_RES_X2I);
    mb_chann->i2x_head = mailbox_get_headptr(mb_chann, CHAN_RES_I2X);
    ...
}

If a maliciously large initial tail index is read, could it force an 
out-of-bounds write in mailbox_send_msg() before normal wrap-around checks 
occur?

drivers/accel/amdxdna/amdxdna_mailbox.c:mailbox_send_msg() {
    ...
    write_addr = mb_chann->mb->res.ringbuf_base + start_addr + tail;
    writel(TOMBSTONE, write_addr);
    ...
}

Should we bound check x2i_tail and i2x_head against rb_size during channel
initialization?

> +		dev_err(mb_chann->mb->dev,
> +			"Mailbox register offset unaligned or outside the %zu byte mapping\n",
> +			mb_chann->mb->res.mbox_size);
> +		return -EINVAL;
> +	}
> +
>  	mb_chann->msix_irq = mb_irq;
>  	mb_chann->iohub_int_addr = iohub_int_addr;
>  	memcpy(&mb_chann->res[CHAN_RES_X2I], x2i, sizeof(*x2i));

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/cover.1789334558.git.0xiviel@gmail.com?part=2

      reply	other threads:[~2026-09-13 21:44 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-13 21:31 [PATCH v2 0/2] accel/amdxdna: stale mailbox channel pointer, unbounded register offsets Eva Crystal
2026-09-13 21:31 ` [PATCH v2 1/2] accel/amdxdna: clear the mailbox channel pointer when starting it fails Eva Crystal
2026-09-13 21:52   ` sashiko-bot
2026-09-15 16:36   ` Lizhi Hou
2026-09-13 21:31 ` [PATCH v2 2/2] accel/amdxdna: bound the firmware-supplied mailbox register offsets Eva Crystal
2026-09-13 21:44   ` sashiko-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=20260913214451.639251F000FF@smtp.kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=0xiviel@gmail.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=sashiko-reviews@lists.linux.dev \
    /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;
as well as URLs for NNTP newsgroup(s).