public inbox for linux-fsdevel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2] fs: Handle multiply claimed blocks more gracefully with mmb
@ 2026-04-23  9:03 Jan Kara
  2026-04-23 11:54 ` Christian Brauner
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Kara @ 2026-04-23  9:03 UTC (permalink / raw)
  To: Christian Brauner; +Cc: linux-fsdevel, Jan Kara, Ruikai Peng

When a metadata block is referenced by multiple inodes and tracked by
metadata bh infrastructure (which is forbidden and generally indicates
filesystem corruption), it can happen that mmb_mark_buffer_dirty() is
called for two different mmb structures in parallel. This can lead to a
corruption of mmb linked list. Handle that situation gracefully (at
least from mmb POV) by serializing on setting bh->b_mmb.

Reported-by: Ruikai Peng <ruikai@pwno.io>
Signed-off-by: Jan Kara <jack@suse.cz>
---
 fs/buffer.c | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

- fix inverted condition

diff --git a/fs/buffer.c b/fs/buffer.c
index d6e062c42a8d..b0b3792b1496 100644
--- a/fs/buffer.c
+++ b/fs/buffer.c
@@ -719,8 +719,15 @@ void mmb_mark_buffer_dirty(struct buffer_head *bh,
 	mark_buffer_dirty(bh);
 	if (!bh->b_mmb) {
 		spin_lock(&mmb->lock);
+		/*
+		 * For a corrupted filesystem with multiply claimed blocks this
+		 * can fail. Avoid corrupting the linked list in that case.
+		 */
+		if (cmpxchg(&bh->b_mmb, NULL, mmb) != NULL) {
+			spin_unlock(&mmb->lock);
+			return;
+		}
 		list_move_tail(&bh->b_assoc_buffers, &mmb->list);
-		bh->b_mmb = mmb;
 		spin_unlock(&mmb->lock);
 	}
 }
-- 
2.51.0


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2] fs: Handle multiply claimed blocks more gracefully with mmb
  2026-04-23  9:03 [PATCH v2] fs: Handle multiply claimed blocks more gracefully with mmb Jan Kara
@ 2026-04-23 11:54 ` Christian Brauner
  0 siblings, 0 replies; 2+ messages in thread
From: Christian Brauner @ 2026-04-23 11:54 UTC (permalink / raw)
  To: Jan Kara; +Cc: Christian Brauner, linux-fsdevel, Ruikai Peng

On Thu, 23 Apr 2026 11:03:12 +0200, Jan Kara wrote:
> When a metadata block is referenced by multiple inodes and tracked by
> metadata bh infrastructure (which is forbidden and generally indicates
> filesystem corruption), it can happen that mmb_mark_buffer_dirty() is
> called for two different mmb structures in parallel. This can lead to a
> corruption of mmb linked list. Handle that situation gracefully (at
> least from mmb POV) by serializing on setting bh->b_mmb.
> 
> [...]

Applied to the vfs.fixes branch of the vfs/vfs.git tree.
Patches in the vfs.fixes branch should appear in linux-next soon.

Please report any outstanding bugs that were missed during review in a
new review to the original patch series allowing us to drop it.

It's encouraged to provide Acked-bys and Reviewed-bys even though the
patch has now been applied. If possible patch trailers will be updated.

Note that commit hashes shown below are subject to change due to rebase,
trailer updates or similar. If in doubt, please check the listed branch.

tree:   https://git.kernel.org/pub/scm/linux/kernel/git/vfs/vfs.git
branch: vfs.fixes

[1/1] fs: Handle multiply claimed blocks more gracefully with mmb
      https://git.kernel.org/vfs/vfs/c/85cd1b6eda78

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-04-23 11:54 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-23  9:03 [PATCH v2] fs: Handle multiply claimed blocks more gracefully with mmb Jan Kara
2026-04-23 11:54 ` Christian Brauner

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox