Received: from smtp.kernel.org (aws-us-west-2-korg-mail-alma10-1.taild15c8.ts.net [100.103.45.18]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7EF703C0600 for ; Tue, 22 Sep 2026 17:50:34 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=100.103.45.18 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790099436; cv=none; b=sYkeFUmRGDnW11iHfqSXNDfP3yox52jKULKr0Y+uYSIkpLzuGt+E8jsWbzKptQ8vuN29EMKkW5nwxfoTeBQTl2J0IO0Tj+bRs26EXDNVAA+WZrfL2p5O6hCM2SXhH4HK+JmAFO7wC4WOv5x5cp6ICXO9FjtEamAi7dr22IRJi5I= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1790099436; c=relaxed/simple; bh=cZ67qDwdDBXW8MnNqXE32Lk/opMdpdJkN6CGBD9TGh8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gQDDA0rSDCbritp7HPQ47CqGyvDez89vAKv/JO24WtjQ5DzzFcfadQYA8xmfAO5nv63YB8vPALpegnDA47eCLtwYXE7CZvoe2wJibIX6IooIetkqRWeWODmQvlNz2m6N/5ETjisHj8Rm48bjckw3b21rjKKkaKEDmMQBbPsh2+A= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=GyE+gVwk; arc=none smtp.client-ip=100.103.45.18 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="GyE+gVwk" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BDC6E1F000FF; Tue, 22 Sep 2026 17:50:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1790099434; bh=ryNYcCwCW3hHpw46qAah668Ubeuy1RtewgH9z2szuw4=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=GyE+gVwkW0+HUfT0gjelaWcpWSReBSzTehE3K9KPRZmGMg+5JaxelAvy0HGuirsiK 8WAE3OPjgaCVm+i37wS5HWdp+fQO1FyU43toOHeztoV05BBKV9IhnguUlAgWmM9Oq8 orduAMI2rlloJJhEuT6wSgB+h3EyChIucWgpgIn6Scc1NT1bTws0ozJydIrak7aJgr OSI5Pv9c9axOF/+3y5nYgYlPAQY9QlAFNAxqldOl7/sEDmyTQHhr7dEY21SP6NGg1O 3EmuWtABUf+j/mjQe7PY5tYA/w6VludGGQywzlQbKcrygu5MiOOR13iBaMP3gizRF0 INt8UjLXHwRYA== From: Sasha Levin To: stable@vger.kernel.org Cc: Fan Wu , Ulf Hansson , Sasha Levin Subject: [PATCH 6.1.y] mmc: hsq: Fix use-after-free in retry work Date: Tue, 22 Sep 2026 13:50:32 -0400 Message-ID: <20260922175032.3306721-1-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <2026092256-daytime-musty-b7f1@gregkh> References: <2026092256-daytime-musty-b7f1@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: Fan Wu [ Upstream commit 5d132990475f02cfa1debe03d50b479432864ebd ] mmc_hsq_pump_requests() queues retry_work when request_atomic() returns -EBUSY; today sdhci-sprd is the only consumer that implements request_atomic(). The work is embedded in a devm-allocated mmc_hsq, but is never cancelled during driver removal. Work still pending at unbind can therefore run after the devm allocation has been released and dereference hsq->mmc and hsq->mrq. Use devm_work_autocancel() to cancel and drain retry_work before the devm allocation is released. By the time devres cleanup begins, mmc_remove_host() has already stopped the host, so no new requests can arm the work. This issue was found by an in-house static analysis tool. Fixes: 6db96e5810e0 ("mmc: host: Introduce the request_atomic() for the host") Cc: stable@vger.kernel.org Assisted-by: Codex:gpt-5.6 Signed-off-by: Fan Wu Signed-off-by: Ulf Hansson [ Adjusted mmc_hsq_init() context for the missing int i declaration and tag_slot[] initialization loop. ] Signed-off-by: Sasha Levin --- drivers/mmc/host/mmc_hsq.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/mmc/host/mmc_hsq.c b/drivers/mmc/host/mmc_hsq.c index 9d35453e7371b..929cdb496cdd7 100644 --- a/drivers/mmc/host/mmc_hsq.c +++ b/drivers/mmc/host/mmc_hsq.c @@ -7,6 +7,7 @@ * Author: Baolin Wang */ +#include #include #include #include @@ -339,6 +340,8 @@ static const struct mmc_cqe_ops mmc_hsq_ops = { int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) { + int ret; + hsq->num_slots = HSQ_NUM_SLOTS; hsq->next_tag = HSQ_INVALID_TAG; @@ -351,7 +354,11 @@ int mmc_hsq_init(struct mmc_hsq *hsq, struct mmc_host *mmc) hsq->mmc->cqe_private = hsq; mmc->cqe_ops = &mmc_hsq_ops; - INIT_WORK(&hsq->retry_work, mmc_hsq_retry_handler); + ret = devm_work_autocancel(mmc_dev(mmc), &hsq->retry_work, + mmc_hsq_retry_handler); + if (ret) + return ret; + spin_lock_init(&hsq->lock); init_waitqueue_head(&hsq->wait_queue); -- 2.53.0