Skip to content

Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference

Shih-Yuan Lee linux-arm-kernel linux-input linux-spi lkml 5 versions In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v5 Latest3 patches 2 repliesIn review
  2. v43 patches 0 repliesSuperseded
  3. v33 patches 0 repliesSuperseded
Earlier versions · 2
VersionPostedPatchesRepliesStatus
v23 patches0 repliesSuperseded
v11 patch1 replySuperseded

Changes in v5 from the cover letter

- Updated both lpss_spi_setup() and mrfld_spi_setup() in spi-pxa2xx-pci.c to consistently respect the force_pio module parameter across all supported PCI devices (avoiding hardcoded DMA enable on Merrifield systems).

Patches in v5 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/3Input: applespi - cancel pending work on driver removedrivers/input/keyboard/applespi.c+2 -01 reply
2/3Input: applespi - fix NULL pointer dereference in tp_dim opendrivers/input/keyboard/applespi.c+7 -10 replies
3/3spi: pxa2xx: disable DMA for Apple MacBook8,1drivers/spi/spi-pxa2xx-pci.c+33 -20 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v5 yet.

Read the v5 thread

Cover letter [PATCH v5 0/3] Input/SPI: fixes for MacBook8,1 DMA timeout, UAF, and NULL pointer dereference

Hi Dmitry, Mark, and the linux-input/linux-spi community,

This patch series addresses a long-standing DMA initialization timeout on the early 2015 12" MacBook (MacBook8,1) on any boot (including cold boot), as well as two pre-existing, high-severity UAF/NULL-pointer bugs in the applespi driver.

Changes in v5:
- Updated both lpss_spi_setup() and mrfld_spi_setup() in spi-pxa2xx-pci.c to consistently respect the force_pio module parameter across all supported PCI devices (avoiding hardcoded DMA enable on Merrifield systems).

Changes in v4:
- Reverted the runtime can_dma callback override from applespi.c to avoid architectural layering violation, data races (TOCTOU) with concurrent SPI transfers, and execute-after-free vulnerability upon module unload.
- Moved the DMI quirk forcing PIO mode for MacBook8,1 to the host PCI glue driver (spi-pxa2xx-pci.c) where LPSS setup occurs.
- Formatted the DMI match using a structured pxa2xx_spi_pci_dmi_table and helper function pxa2xx_spi_pci_can_dma().
- Added a force_pio module parameter in spi-pxa2xx-pci.c to allow other users to manually force PIO mode for debugging.

Changes in v3:
- Added a force_pio module parameter to applespi to allow users to manually disable DMA for SPI transfers.
- Resolved the execute-after-free vulnerability by unconditionally restoring the original can_dma callback (even if NULL) in the driver remove path.
- Fixed the probe timing issue by applying the can_dma override at the very beginning of applespi_probe() so that all early initialization transfers safely use PIO mode, and properly restoring it in all probe error paths.
- Documented the Bugzilla link in the commit message of Patch 1.

Changes in v2:
- Fixed an unbind/remove execute-after-free vulnerability by storing and restoring the host controller's original can_dma callback in applespi_probe() and applespi_remove().
- Split the fixes into a 3-patch logical series.

Patch 1 fixes a pre-existing UAF vulnerability in the driver unbind path by explicitly calling cancel_work_sync() on the asynchronous registration worker work struct before devres frees the driver private data.

Patch 2 fixes a pre-existing race condition in the debugfs interface where userspace could open the tp_dim file before the asynchronous worker has finished initializing applespi->touchpad_input_dev, leading to a NULL pointer dereference. We resolve this using smp_load_acquire() and checking for NULL.

Patch 3 introduces a structured DMI quirk and a force_pio module parameter in spi-pxa2xx-pci.c to disable DMA on MacBook8,1. This forces the controller to use the rock-solid PIO mode from the very beginning.

Best regards,
Shih-Yuan Lee

Shih-Yuan Lee (3):
Input: applespi - cancel pending work on driver remove
Input: applespi - fix NULL pointer dereference in tp_dim open
spi: pxa2xx: disable DMA for Apple MacBook8,1

 drivers/input/keyboard/applespi.c | 10 ++++++++-
 drivers/spi/spi-pxa2xx-pci.c      | 35 +++++++++++++++++++++++++++++--
 2 files changed, 42 insertions(+), 3 deletions(-)
Signature · 1 line
2.39.5