Skip to content

Commit 6acd87d

Browse files
siddhpanthsiangkao
authored andcommitted
erofs/zmap.c: Fix incorrect offset calculation
Effective offset to add to length was being incorrectly calculated, which resulted in iomap->length being set to 0, triggering a WARN_ON in iomap_iter_done(). Fix that, and describe it in comments. This was reported as a crash by syzbot under an issue about a warning encountered in iomap_iter_done(), but unrelated to erofs. C reproducer: https://syzkaller.appspot.com/text?tag=ReproC&x=1037a6b2880000 Kernel config: https://syzkaller.appspot.com/text?tag=KernelConfig&x=e2021a61197ebe02 Dashboard link: https://syzkaller.appspot.com/bug?extid=a8e049cd3abd342936b6 Reported-by: [email protected] Suggested-by: Gao Xiang <[email protected]> Signed-off-by: Siddh Raman Pant <[email protected]> Reviewed-by: Gao Xiang <[email protected]> Reviewed-by: Chao Yu <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Gao Xiang <[email protected]>
1 parent 88603b6 commit 6acd87d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

fs/erofs/zmap.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -793,12 +793,16 @@ static int z_erofs_iomap_begin_report(struct inode *inode, loff_t offset,
793793
iomap->type = IOMAP_HOLE;
794794
iomap->addr = IOMAP_NULL_ADDR;
795795
/*
796-
* No strict rule how to describe extents for post EOF, yet
797-
* we need do like below. Otherwise, iomap itself will get
796+
* No strict rule on how to describe extents for post EOF, yet
797+
* we need to do like below. Otherwise, iomap itself will get
798798
* into an endless loop on post EOF.
799+
*
800+
* Calculate the effective offset by subtracting extent start
801+
* (map.m_la) from the requested offset, and add it to length.
802+
* (NB: offset >= map.m_la always)
799803
*/
800804
if (iomap->offset >= inode->i_size)
801-
iomap->length = length + map.m_la - offset;
805+
iomap->length = length + offset - map.m_la;
802806
}
803807
iomap->flags = 0;
804808
return 0;

0 commit comments

Comments
 (0)