From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41DB7BA3D for ; Fri, 17 Jul 2026 00:08:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.199 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784246893; cv=none; b=eFw5WAt5V7VOTVILospFK5ZrI5YfJSYYHYTjmDGy1CaHifNZpD8aihKqSjtpmsc4Vmvf0AzqTvy9nbt+rbw+DFDozFnnYbjv4QazxCkbSuz+8pNUtynOFAMVB5vmQn51okSxLutJJR73y+jMIecCB0jM8Z8z8cmxP118FA5fSbg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784246893; c=relaxed/simple; bh=4Q0kRJhVEOtGzkcigylnRuTplRbw3stYk7QWfF5YmNA=; h=MIME-Version:Date:In-Reply-To:Message-ID:Subject:From:To: Content-Type; b=Fy0KVM4W3Gqole5x7RuF2lDDOz28hDGxzkkvOoY2SlBVfc0cViD2yVGhF3TOORrniFr6GEknFh9P645oTHLEjSmTv5mO6imVYH2o7O/nSXYtULk1tFKRMi/6rGjVoy0O9HRM3vlMdjcGI2MRh9huZnkbd4aFWKUqRit23QvtSUg= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com; arc=none smtp.client-ip=209.85.167.199 Authentication-Results: smtp.subspace.kernel.org; dmarc=fail (p=none dis=none) header.from=syzkaller.appspotmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=M3KW2WVRGUFZ5GODRSRYTGD7.apphosting.bounces.google.com Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-495b8120909so11608379b6e.1 for ; Thu, 16 Jul 2026 17:08:12 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784246891; x=1784851691; h=content-type:to:from:subject:message-id:in-reply-to:date :mime-version:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to:content-type; bh=iagjpbnmS2tTiBASwZNLNKX1DBsVfjh+1e4LAl04JZM=; b=sNn8CxDIrnq+aVSLoSJKhTftpgqcqdTjRQPVawk8fWyacF/q1YMSL9kAsPfZdUpVFA 6jtCMokP/bTm0MK5CqevOo56VcjyGW77FPmKwxGBIOa2nGj+MHrDQlIAA4b+U6KSNAGQ +60GjdrTf9719fM9/nS7/+eI45Pns37ejL6e/LfGYxMEU1XMFFuUYaBzJh9VpHGrMoRj 6BP8y3VIQNSE5iwSUFHF7zF6W73O8fMf7saqX52UPFBEXNi6pmuhIFg7y7pmIxRhDOMQ 5uSIayKvSyc+HRx8m4ltp+W1IpwDCw+usVlAHNQEvPiOxgXR1pBWAUdEu0cWim9nENZ5 A9GQ== X-Gm-Message-State: AOJu0YygOU6dZfrhNHsvstIezuqYAEOkC52r2uqpdjJIGC6/Kvev+6+E zKQAH+VstIH+LYYJLnVJLeoz7TMsl2hkYdmG4WuEhO3zQBWRynHXbe5sXzKuFlaglZDLe1H9idl 1UwNKQTHKPzE0vKAznV6nBm6hxK3cmgDfIDLQX+YQ+fwIVECMilsJhUIkHRM= Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Received: by 2002:a05:6808:1406:b0:49a:1ada:53da with SMTP id 5614622812f47-4a4d04ffc68mr24975b6e.34.1784246890969; Thu, 16 Jul 2026 17:08:10 -0700 (PDT) Date: Thu, 16 Jul 2026 17:08:10 -0700 In-Reply-To: <6a588d44.c96faac9.59e0.0012.GAE@google.com> X-Google-Appengine-App-Id: s~syzkaller X-Google-Appengine-App-Id-Alias: syzkaller Message-ID: <6a59726a.42649fcc.a68e.05d0.GAE@google.com> Subject: Forwarded: [PATCH] ext4: fix race condition in ext4_write_end() with inline data conversion From: syzbot To: linux-kernel@vger.kernel.org, syzkaller-bugs@googlegroups.com Content-Type: text/plain; charset="UTF-8" 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 --- 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