The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [PATCH] mtd: virt_concat: fix use-after-free in mtd_virt_concat_destroy_joins()
@ 2026-06-14  8:10 Harshit Mogalapalli
  2026-06-16  9:51 ` Luca Ceresoli
  2026-06-16 12:25 ` Harshit Mogalapalli
  0 siblings, 2 replies; 4+ messages in thread
From: Harshit Mogalapalli @ 2026-06-14  8:10 UTC (permalink / raw)
  To: Miquel Raynal, Richard Weinberger, Vignesh Raghavendra,
	Amit Kumar Mahapatra, Luca Ceresoli, linux-mtd, linux-kernel
  Cc: kernel-janitors, error27, Harshit Mogalapalli

mtd_concat_destroy() frees item->concat so calling
mtd_virt_concat_put_mtd_devices(item->concat) leads to a use after free.

Fix this 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>
---
This is static analysis finding by Smatch, only compile tested.
---
 drivers/mtd/mtd_virt_concat.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/mtd/mtd_virt_concat.c b/drivers/mtd/mtd_virt_concat.c
index 37075ead0f33..a3fb96788e9d 100644
--- a/drivers/mtd/mtd_virt_concat.c
+++ b/drivers/mtd/mtd_virt_concat.c
@@ -75,8 +75,8 @@ void mtd_virt_concat_destroy_joins(void)
 		if (item->concat) {
 			mtd_device_unregister(mtd);
 			kfree(mtd->name);
-			mtd_concat_destroy(mtd);
 			mtd_virt_concat_put_mtd_devices(item->concat);
+			mtd_concat_destroy(mtd);
 		}
 	}
 }
-- 
2.50.1


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

end of thread, other threads:[~2026-06-16 12:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-06-14  8:10 [PATCH] mtd: virt_concat: fix use-after-free in mtd_virt_concat_destroy_joins() Harshit Mogalapalli
2026-06-16  9:51 ` Luca Ceresoli
2026-06-16 10:13   ` Dan Carpenter
2026-06-16 12:25 ` Harshit Mogalapalli

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