Linux MultiMedia Card development
 help / color / mirror / Atom feed
* [PATCH v2] mmc: vub300: fix use-after-free in vub300 teardown
@ 2026-09-08 15:09 Adriano Cordova
  2026-09-08 15:51 ` Johan Hovold
  0 siblings, 1 reply; 2+ messages in thread
From: Adriano Cordova @ 2026-09-08 15:09 UTC (permalink / raw)
  To: Ulf Hansson
  Cc: Stephen Boyd, Johan Hovold, linux-mmc, linux-kernel,
	Adriano Cordova, syzbot+f312381a95cc080992fd, stable

mmc_host_classdev_release() reads host->parent->of_node, but the
parent is not guaranteed to outlive the host. Instead, store
host->index_is_alias to avoid reading the parent at release time.

Also, call kref_put() after mmc_request_done(), as the latter
dereferences the host pointer.

Fixes: 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")
Reported-by: syzbot+f312381a95cc080992fd@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=f312381a95cc080992fd
Assisted-by: opencode: deepseek v4 flash
Cc: stable@vger.kernel.org
Signed-off-by: Adriano Cordova <adrianox@gmail.com>
---
 drivers/mmc/core/host.c   | 3 ++-
 drivers/mmc/host/vub300.c | 4 ++--
 include/linux/mmc/host.h  | 1 +
 3 files changed, 5 insertions(+), 3 deletions(-)

diff --git a/drivers/mmc/core/host.c b/drivers/mmc/core/host.c
index b7ce3137d452..542bb033c6da 100644
--- a/drivers/mmc/core/host.c
+++ b/drivers/mmc/core/host.c
@@ -67,7 +67,7 @@ static void mmc_host_classdev_release(struct device *dev)
 {
 	struct mmc_host *host = cls_dev_to_mmc_host(dev);
 	wakeup_source_unregister(host->ws);
-	if (of_alias_get_id(host->parent->of_node, "mmc") < 0)
+	if (!host->index_is_alias)
 		ida_free(&mmc_host_ida, host->index);
 	kfree(host);
 }
@@ -538,6 +538,7 @@ struct mmc_host *mmc_alloc_host(int extra, struct device *dev)
 	}
 
 	host->index = index;
+	host->index_is_alias = (alias_id >= 0);
 
 	dev_set_name(&host->class_dev, "mmc%d", host->index);
 	host->ws = wakeup_source_register(NULL, dev_name(&host->class_dev));
diff --git a/drivers/mmc/host/vub300.c b/drivers/mmc/host/vub300.c
index 2dae474dcd06..c87c54aa0e99 100644
--- a/drivers/mmc/host/vub300.c
+++ b/drivers/mmc/host/vub300.c
@@ -1794,8 +1794,8 @@ static void vub300_cmndwork_thread(struct work_struct *work)
 			construct_request_response(vub300, cmd);
 			vub300->resp_len = 0;
 			mutex_unlock(&vub300->cmd_mutex);
-			kref_put(&vub300->kref, vub300_delete);
 			mmc_request_done(vub300->mmc, req);
+			kref_put(&vub300->kref, vub300_delete);
 			return;
 		}
 	}
@@ -1946,8 +1946,8 @@ static void vub300_mmc_request(struct mmc_host *mmc, struct mmc_request *req)
 		    satisfy_request_from_offloaded_data(vub300, cmd)) {
 			cmd->error = 0;
 			mutex_unlock(&vub300->cmd_mutex);
-			kref_put(&vub300->kref, vub300_delete);
 			mmc_request_done(mmc, req);
+			kref_put(&vub300->kref, vub300_delete);
 			return;
 		} else {
 			vub300->cmd = cmd;
diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h
index ba84f02c2a10..165d24104d3c 100644
--- a/include/linux/mmc/host.h
+++ b/include/linux/mmc/host.h
@@ -356,6 +356,7 @@ struct mmc_host {
 	struct device		*parent;
 	struct device		class_dev;
 	int			index;
+	bool			index_is_alias;
 	const struct mmc_host_ops *ops;
 	struct mmc_pwrseq	*pwrseq;
 	unsigned int		f_min;
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] mmc: vub300: fix use-after-free in vub300 teardown
  2026-09-08 15:09 [PATCH v2] mmc: vub300: fix use-after-free in vub300 teardown Adriano Cordova
@ 2026-09-08 15:51 ` Johan Hovold
  0 siblings, 0 replies; 2+ messages in thread
From: Johan Hovold @ 2026-09-08 15:51 UTC (permalink / raw)
  To: Adriano Cordova
  Cc: Ulf Hansson, Stephen Boyd, linux-mmc, linux-kernel,
	syzbot+f312381a95cc080992fd, stable

On Tue, Sep 08, 2026 at 12:09:00PM -0300, Adriano Cordova wrote:
> mmc_host_classdev_release() reads host->parent->of_node, but the
> parent is not guaranteed to outlive the host. Instead, store
> host->index_is_alias to avoid reading the parent at release time.
> 
> Also, call kref_put() after mmc_request_done(), as the latter
> dereferences the host pointer.

These are two separate issues and should be fixed separately.

> Fixes: 88095e7b473a ("mmc: Add new VUB300 USB-to-SD/SDIO/MMC driver")

This is not the commit that introduced the of_node issue.

> Reported-by: syzbot+f312381a95cc080992fd@syzkaller.appspotmail.com
> Link: https://syzkaller.appspot.com/bug?extid=f312381a95cc080992fd
> Assisted-by: opencode: deepseek v4 flash
> Cc: stable@vger.kernel.org
> Signed-off-by: Adriano Cordova <adrianox@gmail.com>
> ---
>  drivers/mmc/core/host.c   | 3 ++-
>  drivers/mmc/host/vub300.c | 4 ++--
>  include/linux/mmc/host.h  | 1 +
>  3 files changed, 5 insertions(+), 3 deletions(-)

Johan

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-09-08 15:51 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-09-08 15:09 [PATCH v2] mmc: vub300: fix use-after-free in vub300 teardown Adriano Cordova
2026-09-08 15:51 ` Johan Hovold

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox