Skip to content

Commit cc97093

Browse files
author
CKI Backport Bot
committed
iomap: add a workaround for racy i_size updates on block devices
JIRA: https://issues.redhat.com/browse/RHEL-79099 commit 381c043 Author: Christoph Hellwig <hch@lst.de> Date: Mon Sep 25 08:54:45 2023 -0700 iomap: add a workaround for racy i_size updates on block devices A szybot reproducer that does write I/O while truncating the size of a block device can end up in clean_bdev_aliases, which tries to clean the bdev aliases that it uses. This is because iomap_to_bh automatically sets the BH_New flag when outside of i_size. For block devices updates to i_size are racy and we can hit this case in a tiny race window, leading to the eventual clean_bdev_aliases call. Fix this by erroring out of > i_size I/O on block devices. Reported-by: syzbot+1fa947e7f09e136925b8@syzkaller.appspotmail.com Signed-off-by: Christoph Hellwig <hch@lst.de> Tested-by: syzbot+1fa947e7f09e136925b8@syzkaller.appspotmail.com Reviewed-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: Darrick J. Wong <djwong@kernel.org> Signed-off-by: CKI Backport Bot <cki-ci-bot+cki-gitlab-backport-bot@redhat.com>
1 parent ef2902a commit cc97093

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

fs/buffer.c

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2014,8 +2014,17 @@ iomap_to_bh(struct inode *inode, sector_t block, struct buffer_head *bh,
20142014
fallthrough;
20152015
case IOMAP_MAPPED:
20162016
if ((iomap->flags & IOMAP_F_NEW) ||
2017-
offset >= i_size_read(inode))
2017+
offset >= i_size_read(inode)) {
2018+
/*
2019+
* This can happen if truncating the block device races
2020+
* with the check in the caller as i_size updates on
2021+
* block devices aren't synchronized by i_rwsem for
2022+
* block devices.
2023+
*/
2024+
if (S_ISBLK(inode->i_mode))
2025+
return -EIO;
20182026
set_buffer_new(bh);
2027+
}
20192028
bh->b_blocknr = (iomap->addr + offset - iomap->offset) >>
20202029
inode->i_blkbits;
20212030
set_buffer_mapped(bh);

0 commit comments

Comments
 (0)