Skip to content

Commit ca19808

Browse files
james010kimmiquelraynal
authored andcommitted
mtd: docg3: fix use-after-free in docg3_release()
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: c8ae3f7 ("lib/bch: Rework a little bit the exported function names") Cc: stable@vger.kernel.org Signed-off-by: James Kim <james010kim@gmail.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent e19eaff commit ca19808

1 file changed

Lines changed: 1 addition & 2 deletions

File tree

drivers/mtd/devices/docg3.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2049,15 +2049,14 @@ static int __init docg3_probe(struct platform_device *pdev)
20492049
static void docg3_release(struct platform_device *pdev)
20502050
{
20512051
struct docg3_cascade *cascade = platform_get_drvdata(pdev);
2052-
struct docg3 *docg3 = cascade->floors[0]->priv;
20532052
int floor;
20542053

20552054
doc_unregister_sysfs(pdev, cascade);
20562055
for (floor = 0; floor < DOC_MAX_NBFLOORS; floor++)
20572056
if (cascade->floors[floor])
20582057
doc_release_device(cascade->floors[floor]);
20592058

2060-
bch_free(docg3->cascade->bch);
2059+
bch_free(cascade->bch);
20612060
}
20622061

20632062
#ifdef CONFIG_OF

0 commit comments

Comments
 (0)