]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
mtd: virt_concat: fix use-after-free in mtd_virt_concat_destroy()
authorHarshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Tue, 16 Jun 2026 10:14:39 +0000 (03:14 -0700)
committerMiquel Raynal <miquel.raynal@bootlin.com>
Mon, 29 Jun 2026 14:40:13 +0000 (16:40 +0200)
mtd_concat_destroy() frees item->concat so calling
mtd_virt_concat_put_mtd_devices(item->concat) after that leads to a
use-after-free.

Fix it by moving mtd_virt_concat_put_mtd_devices() before
mtd_concat_destroy().

Fixes: 43db6366fc2d ("mtd: Add driver for concatenating devices")
Signed-off-by: Harshit Mogalapalli <harshit.m.mogalapalli@oracle.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
drivers/mtd/mtd_virt_concat.c

index a3fb96788e9dc8b2bbd1a9a55687f4b4c9579fbe..c872a882771858cbe956338eee9dfc497f30628f 100644 (file)
@@ -126,8 +126,8 @@ int mtd_virt_concat_destroy(struct mtd_info *mtd)
                if (concat->mtd.name) {
                        del_mtd_device(&concat->mtd);
                        kfree(concat->mtd.name);
-                       mtd_concat_destroy(&concat->mtd);
                        mtd_virt_concat_put_mtd_devices(item->concat);
+                       mtd_concat_destroy(&concat->mtd);
                }
 
                for (idx = 0; idx < item->count; idx++)