From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A5864481B3 for ; Mon, 19 Feb 2024 18:29:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367395; cv=none; b=Anz0FBbQFTlrWGQztfp8ctoORNfBlDRQ/t4eIW6+rlfUlZyQHVR3R0MnFqbRjwRWszKCl44cSuhT/EOUOptMeXPK+pVf+H/ou2K6ZumncngjJWehnT9JnFLfLdpG7VUMQjjw85pIT2k0aS2Z9zjUUzZjv0OPFj8S4W28Icz/mnE= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708367395; c=relaxed/simple; bh=eIoosv/4eQjqZDNKO2Uu5N0v1NsclLpefp+pPA7pQfs=; h=Subject:To:Cc:From:Date:Message-ID:MIME-Version:Content-Type; b=AaZu0wFDq2GpSe5cgotLtejcJP/11iU4aJYs8pc58SflEQaf6sFXei/cDayy2VBbmHs2jyEtb591W4rc5eWMdqGMn2EoLJWODQuo8JTw/zSVZeB2xuUAhpR5NK5XTwHYpuEUm6ppzyhX19CQw2/fnyhkj7H+xwZHfqoD0kh8bBU= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=HFu7m6ui; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="HFu7m6ui" Received: by smtp.kernel.org (Postfix) with ESMTPSA id AE80AC433F1; Mon, 19 Feb 2024 18:29:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1708367395; bh=eIoosv/4eQjqZDNKO2Uu5N0v1NsclLpefp+pPA7pQfs=; h=Subject:To:Cc:From:Date:From; b=HFu7m6ui2bQFDZT+a6HgqVjkgyFsHNwLDDlGUZxkKLNQ9fxL7xInlH6vbzWKI1H70 ItMTOyHBWNy68yZU3SB703jFbbYk/PeazA0Djy4wdveaGTXRVzKJ+0sFHYeLWHILCZ mPiRQJ1CDrcNlKZdLmnR3W1Cr4VdXvT5Ts3RzPKQ= Subject: FAILED: patch "[PATCH] nilfs2: fix potential bug in end_buffer_async_write" failed to apply to 5.15-stable tree To: konishi.ryusuke@gmail.com,akpm@linux-foundation.org,stable@vger.kernel.org Cc: From: Date: Mon, 19 Feb 2024 19:29:46 +0100 Message-ID: <2024021945-output-concave-3ad1@gregkh> Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=ANSI_X3.4-1968 Content-Transfer-Encoding: 8bit The patch below does not apply to the 5.15-stable tree. If someone wants it applied there, or to any other stable or longterm tree, then please email the backport, including the original git commit id to . To reproduce the conflict and resubmit, you may use the following commands: git fetch https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/ linux-5.15.y git checkout FETCH_HEAD git cherry-pick -x 5bc09b397cbf1221f8a8aacb1152650c9195b02b # git commit -s git send-email --to '' --in-reply-to '2024021945-output-concave-3ad1@gregkh' --subject-prefix 'PATCH 5.15.y' HEAD^.. Possible dependencies: 5bc09b397cbf ("nilfs2: fix potential bug in end_buffer_async_write") ff5710c3f3c2 ("nilfs2: convert nilfs_segctor_prepare_write to use folios") 3cd36212bf75 ("nilfs2: convert nilfs_segctor_complete_write to use folios") 50196f0081ca ("nilfs2: convert nilfs_abort_logs to use folios") 8f46eaf6fd84 ("nilfs2: add nilfs_end_folio_io()") 679bd7ebdd31 ("nilfs2: fix buffer corruption due to concurrent device reads") thanks, greg k-h ------------------ original commit in Linus's tree ------------------ >From 5bc09b397cbf1221f8a8aacb1152650c9195b02b Mon Sep 17 00:00:00 2001 From: Ryusuke Konishi Date: Sun, 4 Feb 2024 01:16:45 +0900 Subject: [PATCH] nilfs2: fix potential bug in end_buffer_async_write According to a syzbot report, end_buffer_async_write(), which handles the completion of block device writes, may detect abnormal condition of the buffer async_write flag and cause a BUG_ON failure when using nilfs2. Nilfs2 itself does not use end_buffer_async_write(). But, the async_write flag is now used as a marker by commit 7f42ec394156 ("nilfs2: fix issue with race condition of competition between segments for dirty blocks") as a means of resolving double list insertion of dirty blocks in nilfs_lookup_dirty_data_buffers() and nilfs_lookup_node_buffers() and the resulting crash. This modification is safe as long as it is used for file data and b-tree node blocks where the page caches are independent. However, it was irrelevant and redundant to also introduce async_write for segment summary and super root blocks that share buffers with the backing device. This led to the possibility that the BUG_ON check in end_buffer_async_write would fail as described above, if independent writebacks of the backing device occurred in parallel. The use of async_write for segment summary buffers has already been removed in a previous change. Fix this issue by removing the manipulation of the async_write flag for the remaining super root block buffer. Link: https://lkml.kernel.org/r/20240203161645.4992-1-konishi.ryusuke@gmail.com Fixes: 7f42ec394156 ("nilfs2: fix issue with race condition of competition between segments for dirty blocks") Signed-off-by: Ryusuke Konishi Reported-by: syzbot+5c04210f7c7f897c1e7f@syzkaller.appspotmail.com Closes: https://lkml.kernel.org/r/00000000000019a97c05fd42f8c8@google.com Cc: Signed-off-by: Andrew Morton diff --git a/fs/nilfs2/segment.c b/fs/nilfs2/segment.c index 2590a0860eab..2bfb08052d39 100644 --- a/fs/nilfs2/segment.c +++ b/fs/nilfs2/segment.c @@ -1703,7 +1703,6 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { - set_buffer_async_write(bh); if (bh == segbuf->sb_super_root) { if (bh->b_folio != bd_folio) { folio_lock(bd_folio); @@ -1714,6 +1713,7 @@ static void nilfs_segctor_prepare_write(struct nilfs_sc_info *sci) } break; } + set_buffer_async_write(bh); if (bh->b_folio != fs_folio) { nilfs_begin_folio_io(fs_folio); fs_folio = bh->b_folio; @@ -1800,7 +1800,6 @@ static void nilfs_abort_logs(struct list_head *logs, int err) list_for_each_entry(bh, &segbuf->sb_payload_buffers, b_assoc_buffers) { - clear_buffer_async_write(bh); if (bh == segbuf->sb_super_root) { clear_buffer_uptodate(bh); if (bh->b_folio != bd_folio) { @@ -1809,6 +1808,7 @@ static void nilfs_abort_logs(struct list_head *logs, int err) } break; } + clear_buffer_async_write(bh); if (bh->b_folio != fs_folio) { nilfs_end_folio_io(fs_folio, err); fs_folio = bh->b_folio; @@ -1896,8 +1896,9 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) BIT(BH_Delay) | BIT(BH_NILFS_Volatile) | BIT(BH_NILFS_Redirected)); - set_mask_bits(&bh->b_state, clear_bits, set_bits); if (bh == segbuf->sb_super_root) { + set_buffer_uptodate(bh); + clear_buffer_dirty(bh); if (bh->b_folio != bd_folio) { folio_end_writeback(bd_folio); bd_folio = bh->b_folio; @@ -1905,6 +1906,7 @@ static void nilfs_segctor_complete_write(struct nilfs_sc_info *sci) update_sr = true; break; } + set_mask_bits(&bh->b_state, clear_bits, set_bits); if (bh->b_folio != fs_folio) { nilfs_end_folio_io(fs_folio, 0); fs_folio = bh->b_folio;