From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796381177; b=Tlhu/AP3emROvmlHA2aZD7+Ow8NAIOQ5P+cKqcv9QyUmkECYfKGoCux9OQa9BHv0SjFS Qvto4csxLQCBfnBj+MWSKBa4L01eQbI48kcHOeE2ZVpAKv1aGlD1M2L0Ucb16pDqCv10i /vadW4wZ1R2BVIzqAF9QaC+fF1g8ZTm7P+3JVFh1RaXrJRXQe4+F/MmzG2ThtQTYuf9K0 Gx3A6DOC+o4kqiM6FDp5S6BbJl60FvE1ozQeKoMSpszhZy3z62FTMKV6Lm3RLtv37fITQ fkfTJSl4/JS2H5b/siCLTj1bWanjaf9etfERFm8AlK8p+Fre6ZWUuxtIzhSUDEH0D/w== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796381177; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=csj0Gk6p7HuhWYxC0AtuWavWPKdNBVHHVvu99FRQ+lg=; b=1dX42bm1KXDkfGQn6KMs7OiNRMh582G5GmgIEzkJRbwQWRFsZiksM8nlnrXFjMMPj1YZ E102NeNmo66sOsXhvRD6O8yXYf0M7QxfSUGFV4DMJWLDMmqBbzh8zOVMkDnBQPMPAFiQ2 7L/TMo6skc+BzTKt2zEYVeT76X8uye6/EWCxvX46o9uWsljEFtogymxZfK33KWzCjeMi3 VJRPYlDrqkaalgK6MN46O9skxwl3udZUQ9TUUcXFC1KD3hnfArv/tpgbDMw0bXpWXloW+ Hynfg1+6pi2rtdLvIoWWVDx1QEHx2tiQkzeSvEuFR6tcsN372A5PvCcli5C9CrCn1oQ== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=y+UWgxlG; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 0A2C9606A322; Fri, 4 Dec 2026 10:46:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=y+UWgxlG Received: by smtp.kernel.org (Postfix) with ESMTPSA id 84C3E1F000CE; Fri, 4 Dec 2026 10:46:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796381176; bh=csj0Gk6p7HuhWYxC0AtuWavWPKdNBVHHVvu99FRQ+lg=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=y+UWgxlGPSvETTOl8pRCQOFp3M37z7xL/uyo0yDzh1bNx2xT9u+ZyeLQypaJrSycK 1Mkil85CC/dnKEAUTWYErPNOtCIwmA2uNQcwRgx/WyL4M3v8clGW+0t3KtsN0Mm1ep 6WfxkZmtnI2EKYbFsOWpKPex5ifnT3IAfuEwRp7o= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Zhiyuan Zhang , Andrew Morton , syzbot+42984127d45ad96219de@syzkaller.appspotmail.com, Joseph Qi , Heming Zhao , Mark Fasheh , Joel Becker , yangwenfang Subject: [PATCH 7.3 592/742] ocfs2: fix kernel BUG in ocfs2_page_mkwrite() when write_end fails Date: Fri, 4 Dec 2026 19:07:36 +0900 Message-ID: <20261204100650.851848922@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100635.034361255@linuxfoundation.org> References: <20261204100635.034361255@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 7.3-stable review patch. If anyone has any objections, please let me know. ------------------ From: Zhiyuan Zhang commit 5158f371faceb185235ba42882e67a840cfd7f48 upstream. syzbot reported a kernel BUG in the ocfs2 write fault path: (syz.0.17,5578,0):ocfs2_write_end_nolock:1945 ERROR: status = -30 kernel BUG at fs/ocfs2/mmap.c:106! Call Trace: do_page_mkwrite+0x147/0x310 mm/memory.c:3879 do_shared_fault mm/memory.c:6145 [inline] handle_mm_fault+0x1a53/0x3750 mm/memory.c:6943 __ocfs2_page_mkwrite() calls ocfs2_write_begin_nolock() and then ocfs2_write_end_nolock(), and uses BUG_ON() to assert that the latter returns the full length. But ocfs2_write_end_nolock() can fail: since commit 7f27ec978b0e ("ocfs2: call ocfs2_journal_access_di() before ocfs2_journal_dirty() in ocfs2_write_end_nolock()") it gets journal access to the inode buffer again, because the handle may have been restarted since ocfs2_write_begin_nolock(). That fails with -EROFS or -EIO once the journal has been aborted or jbd2 has seen write errors on the device. The syzbot reproducer gets there by shrinking the backing loop device to zero with LOOP_SET_STATUS while writing to a shared file mapping. Handle the failure instead of crashing. ocfs2_write_end_nolock() leaves the mmap folio locked, because ocfs2_unlock_folios() skips it when w_target_locked is set so that it can be returned with VM_FAULT_LOCKED, and do_page_mkwrite() does not unlock it either when ->page_mkwrite() returns an error. So unlock it and fail the fault; the faulting task gets SIGBUS, like for the other errors in this function. For an mmap write ocfs2_write_end_nolock() returns either len or a negative errno: inline data has already been converted to extents by ocfs2_write_begin_nolock(), and copied is equal to len. The BUG matters for local mounts, where the filesystem is expected to go read-only and keep running after a journal abort. On clustered mounts ocfs2_abort() panics the node anyway as soon as it notices the aborted journal. Link: https://lore.kernel.org/20261111023444.22688-1-zhiyuanzhang912@gmail.com Fixes: 7f27ec978b0e ("ocfs2: call ocfs2_journal_access_di() before ocfs2_journal_dirty() in ocfs2_write_end_nolock()") Signed-off-by: Zhiyuan Zhang Signed-off-by: Andrew Morton Reported-by: Closes: https://syzkaller.appspot.com/bug?extid=42984127d45ad96219de Reviewed-by: Joseph Qi Reviewed-by: Heming Zhao Cc: Mark Fasheh Cc: Joel Becker Cc: yangwenfang Cc: Signed-off-by: Greg Kroah-Hartman fs/ocfs2/mmap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- fs/ocfs2/mmap.c | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) --- a/fs/ocfs2/mmap.c +++ b/fs/ocfs2/mmap.c @@ -103,7 +103,17 @@ static vm_fault_t __ocfs2_page_mkwrite(s goto out; } err = ocfs2_write_end_nolock(mapping, pos, len, len, fsdata); - BUG_ON(err != len); + if (err != len) { + /* + * ocfs2_write_end_nolock() keeps the mmap folio locked so + * that it can be returned to the VM with VM_FAULT_LOCKED. + * On failure nobody else will unlock it, so do it here. + */ + folio_unlock(locked_folio); + mlog_errno(err); + ret = vmf_error(err); + goto out; + } ret = VM_FAULT_LOCKED; out: return ret;