From: sashiko-bot@kernel.org
To: "Shih-Yuan Lee" <fourdollars@debian.org>
Cc: dmitry.torokhov@gmail.com, linux-input@vger.kernel.org
Subject: Re: [PATCH v2 1/3] Input: applespi - force PIO mode on MacBook8,1
Date: Sat, 11 Jul 2026 07:04:04 +0000 [thread overview]
Message-ID: <20260711070404.7F4F91F000E9@smtp.kernel.org> (raw)
In-Reply-To: <20260711065415.7396-2-fourdollars@debian.org>
Thank you for your contribution! Sashiko AI review found 2 potential issue(s) to consider:
- [High] Incomplete restoration of `spi->controller->can_dma` leads to an execute-after-free on module unload if the original callback was NULL.
- [High] Architectural violation and data race due to mutating shared SPI host controller, which is applied too late to prevent DMA timeouts.
--
--- Patch [1]: [PATCH v2 1/3] Input: applespi - force PIO mode on MacBook8,1 ---
commit c3d66aabf4cd47b8a9f7af8039fad4fc085aef5f
Author: Shih-Yuan Lee <fourdollars@debian.org>
Input: applespi - force PIO mode on MacBook8,1
This patch introduces a DMI quirk to force PIO mode on MacBook8,1 laptops.
It overrides the shared SPI controller's can_dma callback to avoid timeout
errors during DMA handshakes, and attempts to restore the original callback
when the driver is removed.
[ ... ]
> --- a/drivers/input/keyboard/applespi.c
> +++ b/drivers/input/keyboard/applespi.c
[ ... ]
> @@ -1788,6 +1800,19 @@ static int applespi_probe(struct spi_device *spi)
> debugfs_create_file("tp_dim", 0400, applespi->debugfs_root, applespi,
> &applespi_tp_dim_fops);
>
> + /*
> + * MacBook8,1's SPI host controller DMA is broken (timeout errors).
> + * Force PIO mode by overriding the controller's can_dma callback.
> + *
> + * Since we modify the shared controller's callback, we save the
> + * original pointer and restore it in applespi_remove().
> + */
> + applespi->original_can_dma = spi->controller->can_dma;
> + if (dmi_match(DMI_PRODUCT_NAME, "MacBook8,1")) {
> + dev_info(&spi->dev, "Disabling DMA for MacBook8,1 SPI to force PIO mode\n");
> + spi->controller->can_dma = applespi_can_not_dma;
> + }
> +
> return 0;
> }
[Severity: High]
Is this too late to prevent the DMA timeouts?
The override occurs at the very end of applespi_probe(). However, early SPI
transfers triggered earlier in the function via applespi_setup_spi() and
applespi_init(), as well as any reads triggered by ACPI GPE interrupts that
were already enabled, will still attempt to use DMA and fail.
Furthermore, does mutating the shared SPI host controller's method table from
a peripheral client driver cause data races with concurrent SPI core
operations? Typically, controller-level hardware quirks need to be implemented
in the SPI host controller driver itself rather than the client driver to
maintain encapsulation and prevent races.
[ ... ]
> @@ -1822,6 +1847,9 @@ static void applespi_remove(struct spi_device *spi)
>
> applespi_drain_reads(applespi);
>
> + if (applespi->original_can_dma)
> + spi->controller->can_dma = applespi->original_can_dma;
> +
> debugfs_remove_recursive(applespi->debugfs_root);
> }
[Severity: High]
Will this leave a dangling pointer in the host controller if the original
callback was NULL?
If the host controller does not natively provide a can_dma callback,
applespi->original_can_dma will be NULL. In that scenario, this conditional
check evaluates to false and skips the restoration entirely.
Once the applespi module is unloaded and unmapped from memory, the shared
host controller will be left pointing to the freed applespi_can_not_dma
function. Any subsequent SPI transfers on the host controller would then
dereference this freed pointer, resulting in an execute-after-free and kernel
panic.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20260711065415.7396-1-fourdollars@debian.org?part=1
next prev parent reply other threads:[~2026-07-11 7:04 UTC|newest]
Thread overview: 25+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-11 5:52 [PATCH 0/1] Input: applespi - force PIO mode on MacBook8,1 Shih-Yuan Lee
2026-07-11 5:52 ` [PATCH 1/1] " Shih-Yuan Lee
2026-07-11 6:00 ` sashiko-bot
2026-07-11 6:54 ` [PATCH v2 0/3] Input: applespi - fixes for DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
2026-07-11 6:54 ` [PATCH v2 1/3] Input: applespi - force PIO mode on MacBook8,1 Shih-Yuan Lee
2026-07-11 7:04 ` sashiko-bot [this message]
2026-07-11 6:54 ` [PATCH v2 2/3] Input: applespi - cancel pending work on driver remove Shih-Yuan Lee
2026-07-11 7:09 ` sashiko-bot
2026-07-11 6:54 ` [PATCH v2 3/3] Input: applespi - fix NULL pointer dereference in tp_dim open Shih-Yuan Lee
2026-07-11 7:08 ` sashiko-bot
2026-07-11 11:49 ` [PATCH v4 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
2026-07-11 11:49 ` [PATCH v4 1/3] Input: applespi - cancel pending work on driver remove Shih-Yuan Lee
2026-07-11 12:05 ` sashiko-bot
2026-07-11 11:49 ` [PATCH v4 2/3] Input: applespi - fix NULL pointer dereference in tp_dim open Shih-Yuan Lee
2026-07-11 12:02 ` sashiko-bot
2026-07-11 11:49 ` [PATCH v4 3/3] spi: pxa2xx: disable DMA for Apple MacBook8,1 Shih-Yuan Lee
2026-07-11 11:58 ` sashiko-bot
2026-07-11 13:11 ` [PATCH v5 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
2026-07-11 13:11 ` [PATCH v5 1/3] Input: applespi - cancel pending work on driver remove Shih-Yuan Lee
2026-07-11 13:26 ` sashiko-bot
2026-07-11 21:55 ` Dmitry Torokhov
2026-07-11 13:11 ` [PATCH v5 2/3] Input: applespi - fix NULL pointer dereference in tp_dim open Shih-Yuan Lee
2026-07-11 13:26 ` sashiko-bot
2026-07-11 13:11 ` [PATCH v5 3/3] spi: pxa2xx: disable DMA for Apple MacBook8,1 Shih-Yuan Lee
2026-07-12 16:05 ` [PATCH v5 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference Shih-Yuan Lee
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=20260711070404.7F4F91F000E9@smtp.kernel.org \
--to=sashiko-bot@kernel.org \
--cc=dmitry.torokhov@gmail.com \
--cc=fourdollars@debian.org \
--cc=linux-input@vger.kernel.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