part_test_ubi() reports success for any block device whose first block it
can read, as soon as a UBI device is attached anywhere in the system. It
never looks at which device it was handed, so any device that has no
partition table of its own is labelled as holding UBI volumes:
=> ut imagemap ubiblock
=> blkmap create x
=> blkmap map x 0 800 mem 0x1000000
=> part list blkmap 0
Partition Map for blkmap device 0 -- Partition Type: ubi
0: vol0
The blkmap there is blank, and vol0 lives on nand2.
Check that the descriptor belongs to the block device ubi_bind() created
before claiming it. cmd/ubi.c and test/boot/imagemap.c already pick that
device out the same way.
Fixes: aa5b67ce2262 ("disk: support UBI partitions")
Signed-off-by: Alexey Charkov <[email protected]>
---
This was discovered while adding additional tests for the GPT layout using
blkmap, where it turned out that a stale UBI partition table gets
recognized on the blkmap where none exists.
CI for this:
https://git.u-boot-project.org/u-boot/contributors/alchark/u-boot/-/pipelines/1327
---
drivers/mtd/ubi/part.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/mtd/ubi/part.c b/drivers/mtd/ubi/part.c
index fb30f45e2135..689f5af95a39 100644
--- a/drivers/mtd/ubi/part.c
+++ b/drivers/mtd/ubi/part.c
@@ -8,6 +8,7 @@
#include <memalign.h>
#include <part.h>
#include <ubi_uboot.h>
+#include <dm/device.h>
static inline struct ubi_device *get_ubi_device(void)
{
@@ -92,6 +93,14 @@ static int part_test_ubi(struct blk_desc *dev_desc)
if (!get_ubi_device())
return -1;
+ /*
+ * Only the block device UBI itself created holds UBI volumes. Without
+ * this, every readable block device in the system is claimed as soon as
+ * a UBI device is attached anywhere.
+ */
+ if (!dev_desc->bdev || dev_desc->bdev->driver != DM_DRIVER_GET(ubi_blk))
+ return -1;
+
if (blk_dread(dev_desc, 0, 1, (ulong *)buffer) != 1)
return -1;
---
base-commit: b8e0086b585791a771416ce51b58ce0097bc0b28
change-id: 20260918-ubi-part-test-b261e36d6a78
Best regards,
--
Alexey Charkov <[email protected]>