Forwarded: [PATCH] ext4: handle inline-to-block file conversion race with error return

syzbot posted 1 patch 1 week ago
There is a newer version of this series
fs/ext4/inline.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
Forwarded: [PATCH] ext4: handle inline-to-block file conversion race with error return
Posted by syzbot 1 week ago
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.

***

Subject: [PATCH] ext4: handle inline-to-block file conversion race with error return
Author: kartikey406@gmail.com

#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci


Replace fatal BUG_ON(!ext4_has_inline_data(inode)) with a defensive check
that returns -EIO when a file has been converted from inline to block
storage during write completion.

A file can transition from inline to block storage via concurrent paths
(mmap, readahead, truncate) while a write completion is in flight. If this
occurs, the write is in an inconsistent state and should not silently
succeed. Returning -EIO signals the error to the caller, allowing proper
retry and preventing silent data corruption.

Reported-by: syzbot+293a57918b36cfae3d48@syzkaller.appspotmail.com
Link: https://syzkaller.appspot.com/bug?extid=293a57918b36cfae3d48
Signed-off-by: Deepanshu Kartikey <kartikey406@gmail.com>
---
 fs/ext4/inline.c | 6 +++++-
 1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/fs/ext4/inline.c b/fs/ext4/inline.c
index 8045e4ff270c..887a153924af 100644
--- a/fs/ext4/inline.c
+++ b/fs/ext4/inline.c
@@ -812,7 +812,11 @@ int ext4_write_inline_data_end(struct inode *inode, loff_t pos, unsigned len,
 			goto out;
 		}
 		ext4_write_lock_xattr(inode, &no_expand);
-		BUG_ON(!ext4_has_inline_data(inode));
+		/* File may have been converted to block storage by concurrent path */
+		if (!ext4_has_inline_data(inode)) {
+			ext4_write_unlock_xattr(inode, &no_expand);
+			return -EIO;
+		}
 
 		/*
 		 * ei->i_inline_off may have changed since
-- 
2.43.0