From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 956741A8F7B for ; Fri, 1 May 2026 23:27:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777678059; cv=none; b=LrWSmUjOOd7YMaQPzAWnOObuzFQRtJuz9yWuiNCmy3sHbYvYq2fc3E7P3cOi4+RDXgcXd1XbVEQBPK2lyurP19tEyi705ao9rbWLKJkWY/0/b6dQ4GZiPOuMB0CEp5ayowE/vsule8w2HvRvVtzTLvvXrhzySRVKcFAvMgG8w14= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1777678059; c=relaxed/simple; bh=g2yvkeso3Y6A9tQWJSwtfEfybm8+PGgkvVOE1TpuOU8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=IVLTU/AQBQcyjK7KL/Tc45eS/DlXyUgze1So9DMaKi2f80XnS/OopsWJEJIFckRyoi4s6hhCO5/ZFXQSdkZ1HRdcJNyXuffpKQWkMroIAM/D91BnpBWo17jBUvGMch2dSMPHTjTpS8s7QT3cG30ko8eAsr8Wgf+w0ZrXvsaijcY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=EbPjHL1x; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="EbPjHL1x" Received: by smtp.kernel.org (Postfix) with ESMTPSA id 0ABEFC2BCC6; Fri, 1 May 2026 23:27:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1777678059; bh=g2yvkeso3Y6A9tQWJSwtfEfybm8+PGgkvVOE1TpuOU8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EbPjHL1xeHm5pDq2pWN6PP5yILOOtc2spaday/YDEjcyca2GIeriATwLN+kXDHBV8 Qm8/fmsGSS2xukm2Jnq7qFO5CmFtp+Pc8SIccVIjkTodE9DHS8Hk3pLTPWMFP5BZHt j9nS0hCKspcmYsk2VAmNGApEGlg89KHMhxEYqLGb3EO+luC+w4w8So2ypN3rlvxlym tugpBN7wv5e37hZcJ2JgghS1ol0xZtBnYhTTf8fzcBBt7+GwViCvo+hjfEvhmepQWQ HWDpk59zAnwqWr7vC/30IY0MAdHArbeUwyMCQAycQlCAx013XI6bMUHF2NP2YoJqP7 oINsCUHXtenOg== From: Sasha Levin To: stable@vger.kernel.org Cc: James Kim , Miquel Raynal , Sasha Levin Subject: [PATCH 6.6.y 2/2] mtd: docg3: fix use-after-free in docg3_release() Date: Fri, 1 May 2026 19:27:36 -0400 Message-ID: <20260501232736.4099049-2-sashal@kernel.org> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260501232736.4099049-1-sashal@kernel.org> References: <2026050108-ozone-wiry-64b4@gregkh> <20260501232736.4099049-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit From: James Kim [ Upstream commit ca19808bc6fac7e29420d8508df569b346b3e339 ] In docg3_release(), the docg3 pointer is obtained from cascade->floors[0]->priv before the loop that calls doc_release_device() on each floor. doc_release_device() frees the docg3 struct via kfree(docg3) at line 1881. After the loop, docg3->cascade->bch dereferences the already-freed pointer. Fix this by accessing cascade->bch directly, which is equivalent since docg3->cascade points back to the same cascade struct, and is already available as a local variable. This also removes the now-unused docg3 local variable. Fixes: c8ae3f744ddc ("lib/bch: Rework a little bit the exported function names") Cc: stable@vger.kernel.org Signed-off-by: James Kim Signed-off-by: Miquel Raynal Signed-off-by: Sasha Levin --- drivers/mtd/devices/docg3.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/mtd/devices/docg3.c b/drivers/mtd/devices/docg3.c index a2b643af70194..e37fb11556479 100644 --- a/drivers/mtd/devices/docg3.c +++ b/drivers/mtd/devices/docg3.c @@ -2049,7 +2049,6 @@ static int __init docg3_probe(struct platform_device *pdev) static void docg3_release(struct platform_device *pdev) { struct docg3_cascade *cascade = platform_get_drvdata(pdev); - struct docg3 *docg3 = cascade->floors[0]->priv; int floor; doc_unregister_sysfs(pdev, cascade); @@ -2057,7 +2056,7 @@ static void docg3_release(struct platform_device *pdev) if (cascade->floors[floor]) doc_release_device(cascade->floors[floor]); - bch_free(docg3->cascade->bch); + bch_free(cascade->bch); } #ifdef CONFIG_OF -- 2.53.0