hc
2024-01-03 2f7c68cb55ecb7331f2381deb497c27155f32faf
kernel/drivers/mtd/ubi/build.c
....@@ -467,6 +467,7 @@
467467 err = ubi_add_volume(ubi, ubi->volumes[i]);
468468 if (err) {
469469 ubi_err(ubi, "cannot add volume %d", i);
470
+ ubi->volumes[i] = NULL;
470471 goto out_volumes;
471472 }
472473 }
....@@ -681,6 +682,21 @@
681682 ubi->vid_hdr_aloffset;
682683 }
683684
685
+ /*
686
+ * Memory allocation for VID header is ubi->vid_hdr_alsize
687
+ * which is described in comments in io.c.
688
+ * Make sure VID header shift + UBI_VID_HDR_SIZE not exceeds
689
+ * ubi->vid_hdr_alsize, so that all vid header operations
690
+ * won't access memory out of bounds.
691
+ */
692
+ if ((ubi->vid_hdr_shift + UBI_VID_HDR_SIZE) > ubi->vid_hdr_alsize) {
693
+ ubi_err(ubi, "Invalid VID header offset %d, VID header shift(%d)"
694
+ " + VID header size(%zu) > VID header aligned size(%d).",
695
+ ubi->vid_hdr_offset, ubi->vid_hdr_shift,
696
+ UBI_VID_HDR_SIZE, ubi->vid_hdr_alsize);
697
+ return -EINVAL;
698
+ }
699
+
684700 /* Similar for the data offset */
685701 ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE;
686702 ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size);
....@@ -873,6 +889,13 @@
873889 return -EINVAL;
874890 }
875891
892
+ /* UBI cannot work on flashes with zero erasesize. */
893
+ if (!mtd->erasesize) {
894
+ pr_err("ubi: refuse attaching mtd%d - zero erasesize flash is not supported\n",
895
+ mtd->index);
896
+ return -EINVAL;
897
+ }
898
+
876899 if (ubi_num == UBI_DEV_NUM_AUTO) {
877900 /* Search for an empty slot in the @ubi_devices array */
878901 for (ubi_num = 0; ubi_num < UBI_MAX_DEVICES; ubi_num++)