mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Guanxin Li <bruceli20040604@gmail.com>
To: Aubin Constans <aubin.constans@microchip.com>,
	Ulf Hansson <ulfh@kernel.org>,
	Nicolas Ferre <nicolas.ferre@microchip.com>,
	Alexandre Belloni <alexandre.belloni@bootlin.com>,
	Claudiu Beznea <claudiu.beznea@tuxon.dev>,
	linux-mmc@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	linux-kernel@vger.kernel.org
Cc: Guanxin Li <bruceli20040604@gmail.com>
Subject: [PATCH] mmc: atmel-mci: fix PDC bounce buffer use-after-free
Date: Tue, 20 Oct 2026 22:07:43 +0800	[thread overview]
Message-ID: <20261020140743.2765011-1-bruceli20040604@gmail.com> (raw)

atmci_remove() currently frees the coherent PDC buffer immediately
after pm_runtime_get_sync(), before the controller and its interrupt
handler have been quiesced.

A pending RXBUFF or TXBUFE interrupt can enter atmci_interrupt() after
the buffer has been freed. For a completed receive transfer,
atmci_pdc_complete() accesses host->buffer while copying received data
to the request scatterlist. When data remains, the interrupt handler
can instead call atmci_pdc_set_both_buf(), which may program
host->buf_phys_addr back into the PDC and make the PDC access a freed
coherent allocation.

The buffer must also remain valid while atmci_cleanup_slot() calls
mmc_remove_host(), since an in-flight request may complete during host
removal and take the same interrupt paths.

Move dma_free_coherent() after the controller is disabled, the timer
and IRQ handler are synchronized, and bh_work is canceled. Keep the
remaining teardown order unchanged so that in-flight requests can
finish before the buffer is released.

Signed-off-by: Guanxin Li <bruceli20040604@gmail.com>
---
 drivers/mmc/host/atmel-mci.c | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/host/atmel-mci.c b/drivers/mmc/host/atmel-mci.c
index 8f4df250a77a..7f1a5864da96 100644
--- a/drivers/mmc/host/atmel-mci.c
+++ b/drivers/mmc/host/atmel-mci.c
@@ -2592,9 +2592,6 @@ static void atmci_remove(struct platform_device *pdev)
 
 	pm_runtime_get_sync(dev);
 
-	if (host->buffer)
-		dma_free_coherent(dev, host->buf_size, host->buffer, host->buf_phys_addr);
-
 	for (i = 0; i < ATMCI_MAX_NR_SLOTS; i++) {
 		if (host->slot[i])
 			atmci_cleanup_slot(host->slot[i], i);
@@ -2612,6 +2609,9 @@ static void atmci_remove(struct platform_device *pdev)
 
 	cancel_work_sync(&host->bh_work);
 
+	if (host->buffer)
+		dma_free_coherent(dev, host->buf_size, host->buffer, host->buf_phys_addr);
+
 	clk_disable_unprepare(host->mck);
 
 	pm_runtime_disable(dev);
-- 
2.43.0


                 reply	other threads:[~2026-10-20 14:07 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20261020140743.2765011-1-bruceli20040604@gmail.com \
    --to=bruceli20040604@gmail.com \
    --cc=alexandre.belloni@bootlin.com \
    --cc=aubin.constans@microchip.com \
    --cc=claudiu.beznea@tuxon.dev \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mmc@vger.kernel.org \
    --cc=nicolas.ferre@microchip.com \
    --cc=ulfh@kernel.org \
    /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

all inboxes | Powered by JetHome®