Skip to content

Commit bc88aa5

Browse files
committed
Merge tag 'ubifs-for-linus-6.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs
Pull UBI fixes from Richard Weinberger: - Fix failure to attach when vid_hdr offset equals the (sub)page size - Fix for a deadlock in UBI's worker thread * tag 'ubifs-for-linus-6.3-rc7' of git://git.kernel.org/pub/scm/linux/kernel/git/rw/ubifs: ubi: Fix failure attaching when vid_hdr offset equals to (sub)page size ubi: Fix deadlock caused by recursively holding work_sem
2 parents a7a55e2 + 1e020e1 commit bc88aa5

2 files changed

Lines changed: 17 additions & 8 deletions

File tree

drivers/mtd/ubi/build.c

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -666,12 +666,6 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
666666
ubi->ec_hdr_alsize = ALIGN(UBI_EC_HDR_SIZE, ubi->hdrs_min_io_size);
667667
ubi->vid_hdr_alsize = ALIGN(UBI_VID_HDR_SIZE, ubi->hdrs_min_io_size);
668668

669-
if (ubi->vid_hdr_offset && ((ubi->vid_hdr_offset + UBI_VID_HDR_SIZE) >
670-
ubi->vid_hdr_alsize)) {
671-
ubi_err(ubi, "VID header offset %d too large.", ubi->vid_hdr_offset);
672-
return -EINVAL;
673-
}
674-
675669
dbg_gen("min_io_size %d", ubi->min_io_size);
676670
dbg_gen("max_write_size %d", ubi->max_write_size);
677671
dbg_gen("hdrs_min_io_size %d", ubi->hdrs_min_io_size);
@@ -689,6 +683,21 @@ static int io_init(struct ubi_device *ubi, int max_beb_per1024)
689683
ubi->vid_hdr_aloffset;
690684
}
691685

686+
/*
687+
* Memory allocation for VID header is ubi->vid_hdr_alsize
688+
* which is described in comments in io.c.
689+
* Make sure VID header shift + UBI_VID_HDR_SIZE not exceeds
690+
* ubi->vid_hdr_alsize, so that all vid header operations
691+
* won't access memory out of bounds.
692+
*/
693+
if ((ubi->vid_hdr_shift + UBI_VID_HDR_SIZE) > ubi->vid_hdr_alsize) {
694+
ubi_err(ubi, "Invalid VID header offset %d, VID header shift(%d)"
695+
" + VID header size(%zu) > VID header aligned size(%d).",
696+
ubi->vid_hdr_offset, ubi->vid_hdr_shift,
697+
UBI_VID_HDR_SIZE, ubi->vid_hdr_alsize);
698+
return -EINVAL;
699+
}
700+
692701
/* Similar for the data offset */
693702
ubi->leb_start = ubi->vid_hdr_offset + UBI_VID_HDR_SIZE;
694703
ubi->leb_start = ALIGN(ubi->leb_start, ubi->min_io_size);

drivers/mtd/ubi/wl.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,7 @@ static int erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk,
575575
* @vol_id: the volume ID that last used this PEB
576576
* @lnum: the last used logical eraseblock number for the PEB
577577
* @torture: if the physical eraseblock has to be tortured
578-
* @nested: denotes whether the work_sem is already held in read mode
578+
* @nested: denotes whether the work_sem is already held
579579
*
580580
* This function returns zero in case of success and a %-ENOMEM in case of
581581
* failure.
@@ -1131,7 +1131,7 @@ static int __erase_worker(struct ubi_device *ubi, struct ubi_work *wl_wrk)
11311131
int err1;
11321132

11331133
/* Re-schedule the LEB for erasure */
1134-
err1 = schedule_erase(ubi, e, vol_id, lnum, 0, false);
1134+
err1 = schedule_erase(ubi, e, vol_id, lnum, 0, true);
11351135
if (err1) {
11361136
spin_lock(&ubi->wl_lock);
11371137
wl_entry_destroy(ubi, e);

0 commit comments

Comments
 (0)