From: syzbot <syzbot+293a57918b36cfae3d48@syzkaller.appspotmail.com>
To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com
Subject: Forwarded: [PATCH] ext4: fix race condition in ext4_write_end() with inline data conversion
Date: Thu, 16 Jul 2026 17:08:10 -0700 [thread overview]
Message-ID: <6a59726a.42649fcc.a68e.05d0.GAE@google.com> (raw)
In-Reply-To: <6a588d44.c96faac9.59e0.0012.GAE@google.com>
For archival purposes, forwarding an incoming command email to
linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com.
***
Subject: [PATCH] ext4: fix race condition in ext4_write_end() with inline data conversion
Author: kartikey406@gmail.com
#syz test: git://git.kernel.org/pub/scm/linux/kernel/git/arm64/linux.git for-kernelci
A race condition exists between ext4_write_end() checking for inline data
and the inline-to-block conversion path clearing the inline flags.
Thread A (write completion):
- Checks ext4_has_inline_data(inode) = TRUE (no lock held)
- Checks EXT4_STATE_MAY_INLINE_DATA = TRUE (no lock held)
Thread B (conversion via mmap/readahead):
- Acquires i_data_sem write lock
- Clears EXT4_INODE_INLINE_DATA flag
- Clears EXT4_STATE_MAY_INLINE_DATA state
- Releases i_data_sem
Thread A (resumes):
- Calls ext4_write_inline_data_end()
- BUG_ON(!ext4_has_inline_data(inode)) fails
- Kernel crashes
The fix is to acquire i_data_sem read lock in ext4_write_end() around
the inline data check and handler, serializing against the conversion
path which holds the write lock.
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/inode.c | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/fs/ext4/inode.c b/fs/ext4/inode.c
index ce99807c5f5b..9a5347907685 100644
--- a/fs/ext4/inode.c
+++ b/fs/ext4/inode.c
@@ -1450,11 +1450,17 @@ static int ext4_write_end(const struct kiocb *iocb,
trace_ext4_write_end(inode, pos, len, copied);
+ down_read(&EXT4_I(inode)->i_data_sem);
+ /* Serialize against inline data conversion (see ext4_convert_inline_data_nolock) */
if (ext4_has_inline_data(inode) &&
- ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA))
- return ext4_write_inline_data_end(inode, pos, len, copied,
+ ext4_test_inode_state(inode, EXT4_STATE_MAY_INLINE_DATA)) {
+ ret = ext4_write_inline_data_end(inode, pos, len, copied,
folio);
+ up_read(&EXT4_I(inode)->i_data_sem);
+ return ret;
+ }
+ up_read(&EXT4_I(inode)->i_data_sem);
copied = block_write_end(pos, len, copied, folio);
/*
* it's important to update i_size while still holding folio lock:
--
2.43.0
next prev parent reply other threads:[~2026-07-17 0:08 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-16 7:50 [syzbot] [ext4?] kernel BUG in ext4_write_inline_data_end (3) syzbot
2026-07-17 0:08 ` syzbot [this message]
2026-07-17 9:15 ` Forwarded: [PATCH] ext4: fix race in ext4_write_inline_data_end() by making it defensive syzbot
2026-07-17 10:53 ` Forwarded: [PATCH] ext4: make ext4_write_inline_data_end() handle file conversion gracefully syzbot
2026-07-17 13:41 ` Forwarded: [PATCH] ext4: handle inline-to-block file conversion race with error return syzbot
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=6a59726a.42649fcc.a68e.05d0.GAE@google.com \
--to=syzbot+293a57918b36cfae3d48@syzkaller.appspotmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=syzkaller-bugs@googlegroups.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.