[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20230523-ubiblock-remove-v1-1-240bed75849b@axis.com>
Date: Tue, 23 May 2023 15:12:16 +0200
From: Vincent Whitchurch <vincent.whitchurch@...s.com>
To: Richard Weinberger <richard@....at>,
Miquel Raynal <miquel.raynal@...tlin.com>,
Vignesh Raghavendra <vigneshr@...com>
CC: <linux-mtd@...ts.infradead.org>, <linux-kernel@...r.kernel.org>,
<kernel@...s.com>, Vincent Whitchurch <vincent.whitchurch@...s.com>
Subject: [PATCH 1/2] ubi: block: Fix use-after-free of gendisk
Do not touch the gendisk after put_disk() to fix this use-after-free:
==================================================
BUG: KASAN: slab-use-after-free in ubiblock_remove
Read of size 4 by task ubiblock/361
Call Trace:
ubiblock_remove (drivers/mtd/ubi/block.c:459 drivers/mtd/ubi/block.c:483)
vol_cdev_ioctl
...
Allocated by task 358:
__alloc_disk_node (block/genhd.c:1377)
__blk_mq_alloc_disk (block/blk-mq.c:4093)
ubiblock_create (drivers/mtd/ubi/block.c:397)
vol_cdev_ioctl
...
Freed by task 0:
bdev_free_inode (block/bdev.c:337)
i_callback
rcu_core
__do_softirq
...
Signed-off-by: Vincent Whitchurch <vincent.whitchurch@...s.com>
---
drivers/mtd/ubi/block.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/drivers/mtd/ubi/block.c b/drivers/mtd/ubi/block.c
index 3711d7f74600..70caec4606cd 100644
--- a/drivers/mtd/ubi/block.c
+++ b/drivers/mtd/ubi/block.c
@@ -448,13 +448,15 @@ int ubiblock_create(struct ubi_volume_info *vi)
static void ubiblock_cleanup(struct ubiblock *dev)
{
+ int first_minor = dev->gd->first_minor;
+
/* Stop new requests to arrive */
del_gendisk(dev->gd);
/* Finally destroy the blk queue */
dev_info(disk_to_dev(dev->gd), "released");
put_disk(dev->gd);
blk_mq_free_tag_set(&dev->tag_set);
- idr_remove(&ubiblock_minor_idr, dev->gd->first_minor);
+ idr_remove(&ubiblock_minor_idr, first_minor);
}
int ubiblock_remove(struct ubi_volume_info *vi)
--
2.34.1
Powered by blists - more mailing lists