* [PATCH] fs: Handle multiply claimed blocks more gracefully with mmb
@ 2026-04-22 14:45 Jan Kara
0 siblings, 0 replies; only message in thread
From: Jan Kara @ 2026-04-22 14:45 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(-)
diff --git a/fs/buffer.c b/fs/buffer.c
index d6e062c42a8d..35e7b63576cf 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)) {
+ 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] only message in thread
only message in thread, other threads:[~2026-04-22 14:45 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-04-22 14:45 [PATCH] fs: Handle multiply claimed blocks more gracefully with mmb Jan Kara
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox