From: sashiko-bot@kernel.org
To: "Tim Michals" <tcmichals@gmail.com>
Cc: conor+dt@kernel.org, robh@kernel.org,
linux-sunxi@lists.linux.dev, devicetree@vger.kernel.org
Subject: Re: [PATCH v2 2/7] mailbox: sun55i: add Allwinner sun55i/sun60i 4-port Message Box driver
Date: Sun, 27 Sep 2026 00:33:02 +0000 [thread overview]
Message-ID: <20260927003302.D69591F000FF@smtp.kernel.org> (raw)
In-Reply-To: <20260927002021.797069-3-tcmichals@gmail.com>
Thank you for your contribution! Sashiko AI review found 4 potential issue(s) to consider:
- [High] mailbox: sun55i: out-of-bounds array write in probe due to unbounded DT irq_cnt
- [High] mailbox: sun55i: incorrect last_tx_done polling condition breaks TX semantics
- [High] mailbox: sun55i: NULL pointer dereference in IRQ handler during teardown
- [High] mailbox: sun55i: lockless multi-IRQ concurrency causes FIFO underflow
--
commit d294abbd2180fd12203dc082ff7e6d574533c041
Author: Tim Michals <tcmichals@gmail.com>
mailbox: sun55i: add Allwinner sun55i/sun60i 4-port Message Box driver
This commit adds a mailbox driver for the 4-port hardware Message Box
controller found on Allwinner sun55i and sun60i SoCs. It implements hardware
FIFO communication across 12 logical channels for multiple heterogeneous cores.
> diff --git a/drivers/mailbox/sun55i-msgbox.c b/drivers/mailbox/sun55i-msgbox.c
> new file mode 100644
> index 0000000000000..928e52e08bad4
> --- /dev/null
> +++ b/drivers/mailbox/sun55i-msgbox.c
> @@ -0,0 +1,375 @@
[ ... ]
> +irqreturn_t sun55i_msgbox_irq(int irq, void *dev_id)
> +{
> + struct sun55i_msgbox *mbox = dev_id;
> + irqreturn_t ret = IRQ_NONE;
> + int i, local_n, p, chan_idx;
> +
> + for (local_n = 0; local_n < SUN55I_NUM_ROUTES; local_n++) {
> + void __iomem *local_base = mbox->regs[0];
[Severity: High]
Does this lockless loop allow multiple concurrent handlers on different CPUs to
inspect and process the same hardware channels simultaneously?
Since sun55i_msgbox_probe() registers the exact same handler for multiple IRQs
using request_irq(), if two remote processors send messages concurrently, both
IRQs fire, executing the handler on different CPUs simultaneously.
Both CPUs would see the same pending bit and race to drain the exact same
channel, leading to a TOCTOU race where the second CPU reads from an empty FIFO,
resulting in a hardware underflow and delivery of a corrupt message.
> + u32 en, stat, pending;
> +
> + en = readl(local_base + SUNXI_MSGBOX_READ_IRQ_ENABLE(local_n));
> + stat = readl(local_base + SUNXI_MSGBOX_READ_IRQ_STATUS(local_n));
> + pending = en & stat;
[ ... ]
> +static bool sun55i_msgbox_last_tx_done(struct mbox_chan *chan)
> +{
> + struct sun55i_msgbox *mbox = to_sun55i_msgbox(chan);
> + int n = chan - mbox->controller.chans;
> + int local_n, p, remote_id, remote_n;
> + u32 count;
> +
> + sun55i_chan_to_route(n, &local_n, &p, &remote_id, &remote_n);
> +
> + count = readl(mbox->regs[remote_id] + SUNXI_MSGBOX_MSG_STATUS(remote_n, p)) & MSG_NUM_MASK;
> + return count < SUN55I_FIFO_MAX;
> +}
[Severity: High]
Does returning true when the FIFO is not full falsely signal transmission
completion to the polling framework?
The mailbox framework polls last_tx_done() to know when a message has been
consumed by the remote processor. Returning true while the message is still in
the FIFO (count < SUN55I_FIFO_MAX) falsely signals completion.
The framework will then prematurely send subsequent messages, leading to a
hardware FIFO overflow and dropped IPC messages.
[ ... ]
> +static int sun55i_msgbox_probe(struct platform_device *pdev)
> +{
[ ... ]
> + irq_cnt = platform_irq_count(pdev);
> + if (irq_cnt < 0) {
> + ret = irq_cnt;
> + goto err_assert_reset;
> + }
> +
> + for (i = 0; i < irq_cnt; i++) {
> + int irq = platform_get_irq(pdev, i);
> +
> + if (irq < 0) {
> + ret = irq;
> + goto err_free_irqs;
> + }
> +
> + ret = request_irq(irq, sun55i_msgbox_irq,
> + IRQF_SHARED, dev_name(dev), mbox);
> + if (ret) {
> + dev_err(dev, "failed to request irq %d: %d\n", irq, ret);
> + goto err_free_irqs;
> + }
> + mbox->irqs[i] = irq;
> + mbox->num_irqs = i + 1;
> + }
[Severity: High]
Can this write overflow the mbox->irqs array if irq_cnt exceeds 4?
The driver retrieves irq_cnt directly from the device tree via
platform_irq_count() without bounds checking. If a device tree provides 5 or
more interrupts, the unconditional loop will write out of bounds of the
fixed-size 4-element mbox->irqs array, corrupting memory of adjacent fields in
the sun55i_msgbox structure.
[ ... ]
> +static void sun55i_msgbox_remove(struct platform_device *pdev)
> +{
> + struct sun55i_msgbox *mbox = platform_get_drvdata(pdev);
> + int local_n, i;
> +
> + mbox_controller_unregister(&mbox->controller);
> +
> + /* Mask hardware interrupts and free IRQs before asserting reset and disabling clock */
[Severity: High]
Does unregistering the controller here before masking hardware interrupts and
freeing IRQs leave a race window open for a NULL pointer dereference?
During device removal, mbox_controller_unregister() calls mbox_free_channel(),
which invokes sun55i_msgbox_shutdown() and clears the chan->cl pointer.
While sun55i_msgbox_shutdown() masks the interrupt via MMIO, it fails to
synchronize the kernel IRQ subsystem via synchronize_irq().
If an interrupt handler is already running concurrently on another CPU, it will
proceed to read the FIFO and invoke mbox_chan_received_data() from
sun55i_msgbox_irq(), which dereferences the now-NULL chan->cl->rx_callback
pointer.
> + for (local_n = 0; local_n < SUN55I_NUM_ROUTES; local_n++)
> + writel(0, mbox->regs[0] + SUNXI_MSGBOX_READ_IRQ_ENABLE(local_n));
> +
> + for (i = 0; i < mbox->num_irqs; i++)
> + free_irq(mbox->irqs[i], mbox);
> +
> + reset_control_assert(mbox->reset);
> + clk_disable_unprepare(mbox->clk);
> +}
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260927002021.797069-1-tcmichals@gmail.com?part=2
next prev parent reply other threads:[~2026-09-27 0:33 UTC|newest]
Thread overview: 35+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-09-22 3:47 [PATCH 0/7] remoteproc/mailbox: add Allwinner A523/A527/T527 E907 RISC-V support Tim Michals
2026-09-22 3:47 ` [PATCH 1/7] dt-bindings: mailbox: add Allwinner sun55i msgbox schema Tim Michals
2026-09-22 3:54 ` sashiko-bot
2026-09-22 8:54 ` Krzysztof Kozlowski
2026-09-22 3:47 ` [PATCH 2/7] mailbox: sun55i: add Allwinner sun55i/sun60i 4-port Message Box driver Tim Michals
2026-09-22 4:00 ` sashiko-bot
2026-09-22 3:47 ` [PATCH 3/7] mailbox: sun55i: add KUnit tests for routing and registers Tim Michals
2026-09-22 3:54 ` sashiko-bot
2026-09-22 3:47 ` [PATCH 4/7] dt-bindings: remoteproc: add allwinner sun55i rproc binding Tim Michals
2026-09-22 3:56 ` sashiko-bot
2026-09-22 8:58 ` Krzysztof Kozlowski
2026-09-22 12:46 ` Rob Herring (Arm)
2026-09-22 3:47 ` [PATCH 5/7] remoteproc: sunxi: add allwinner riscv remoteproc driver Tim Michals
2026-09-22 3:59 ` sashiko-bot
2026-09-22 3:47 ` [PATCH 6/7] remoteproc: sunxi: add KUnit tests for da_to_va address translation Tim Michals
2026-09-22 3:54 ` sashiko-bot
2026-09-22 3:47 ` [PATCH 7/7] arm64: dts: allwinner: add a523 msgbox and remoteproc nodes Tim Michals
2026-09-22 3:59 ` sashiko-bot
2026-09-22 6:34 ` [PATCH 0/7] remoteproc/mailbox: add Allwinner A523/A527/T527 E907 RISC-V support Chen-Yu Tsai
2026-09-27 0:20 ` [PATCH v2 0/7] remoteproc: sunxi: Add Allwinner XuanTie E907 RemoteProc and Message Box support Tim Michals
2026-09-27 0:20 ` [PATCH v2 1/7] dt-bindings: mailbox: add Allwinner sun55i msgbox schema Tim Michals
2026-09-27 0:30 ` sashiko-bot
2026-10-01 6:16 ` Krzysztof Kozlowski
2026-09-27 0:20 ` [PATCH v2 2/7] mailbox: sun55i: add Allwinner sun55i/sun60i 4-port Message Box driver Tim Michals
2026-09-27 0:33 ` sashiko-bot [this message]
2026-09-27 0:20 ` [PATCH v2 3/7] mailbox: sun55i: add KUnit test suite for sun55i msgbox driver Tim Michals
2026-09-27 0:31 ` sashiko-bot
2026-09-27 0:20 ` [PATCH v2 4/7] dt-bindings: remoteproc: add Allwinner sun55i-rproc schema Tim Michals
2026-09-27 0:27 ` sashiko-bot
2026-10-01 6:17 ` Krzysztof Kozlowski
2026-09-27 0:20 ` [PATCH v2 5/7] remoteproc: sunxi: add Allwinner XuanTie RISC-V remoteproc driver Tim Michals
2026-09-27 0:33 ` sashiko-bot
2026-09-27 0:20 ` [PATCH v2 6/7] remoteproc: sunxi: add KUnit test suite for sunxi " Tim Michals
2026-09-27 0:32 ` sashiko-bot
2026-09-27 0:20 ` [PATCH v2 7/7] arm64: dts: allwinner: add a523 msgbox and remoteproc nodes Tim Michals
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=20260927003302.D69591F000FF@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=conor+dt@kernel.org \
--cc=devicetree@vger.kernel.org \
--cc=linux-sunxi@lists.linux.dev \
--cc=robh@kernel.org \
--cc=sashiko-reviews@lists.linux.dev \
--cc=tcmichals@gmail.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