Skip to contentSkip to conversation

iomap: handle iterator position advancing beyond current mapping

PATCH In review Piyush Patle 4 participants 7 messages Feb 2

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 iomap: handle iterator position advancing beyond current mapping

syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes.

This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range.

Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position.

Fixes a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation")
Reported-by [email protected]
---
 fs/iomap/iter.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/iomap/iter.c +7 -0
index c04796f6e57f..466a12b0c094 100644
@@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
 			       &iter->iomap, &iter->srcmap);
 	if (ret < 0)
 		return ret;
+	if (iter->iomap.length &&
+	    iter->iomap.offset + iter->iomap.length <= iter->pos) {
+		iter->iomap.flags |= IOMAP_F_STALE;
+		iomap_iter_reset_iomap(iter);
+		return 1;
+	}
+
 	iomap_iter_done(iter);
 	return 1;
 }
Signature · 1 line
2.34.1
#3 lore raw
Quoted 7 lines · Matthew Wilcox
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Piyush Patle

This link doesn't work. And the commit log has zero details of what's happening either.

Quoted 6 lines

Looks like this one:

https://syzkaller.appspot.com/bug?extid=bd5ca596a01d01bfa083

but there's no reproducer. Looks like it's through the blockdev rather than a filesystem being involved.

Let's wait for a reproducer. The fix looks incorrect for anything I could think of, so I'd rather fix a real bug. Given that lack of reproducer I'm also not confident that it fixes anything. The fact that the Fixes tag points to a merge commit doesn't really increase the trust I have in it either.

#4 lore raw
Quoted 12 lines · Christoph Hellwig
Quoted 11 lines · Matthew Wilcox
Quoted 5 lines · Christoph Hellwig
Quoted 1 line · Piyush Patle

This link doesn't work. And the commit log has zero details of what's happening either.

Looks like this one:

https://syzkaller.appspot.com/bug?extid=bd5ca596a01d01bfa083

Quoted 10 lines
Quoted 2 lines

but there's no reproducer. Looks like it's through the blockdev rather than a filesystem being involved.

Let's wait for a reproducer. The fix looks incorrect for anything I could think of, so I'd rather fix a real bug. Given that lack of reproducer I'm also not confident that it fixes anything. The fact that the Fixes tag points to a merge commit doesn't really increase the trust I have in it either.

+1 to this, FWIW. I've had that syzbot report marked in my inbox expecting (hoping..) it would eventually spit out a reproducer to help better characterize the cause.

This patch just appears to copy the warning check and force a lookup cycle before we trigger it, which I don't think is doing us any favors. At minimum we should have an understanding of precisely how this happens.

Brian

#5 lore raw

PATCH 1/1 iomap: handle iterator position advancing beyond current mapping

In reply to Piyush Patle

syzbot reports a WARN_ON in iomap_iter_done() when iter->pos advances past the end of the current iomap during buffered writes.

This happens when a write completes and updates iter->pos beyond the mapped extent before a new iomap is obtained, violating the invariant that iter->pos must lie within the active iomap range.

Detect this condition early and mark the mapping stale so the iterator restarts with a fresh iomap covering the current position.

Fixes a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation")
Reported-by [email protected]
---
 fs/iomap/iter.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/iomap/iter.c +7 -0
index c04796f6e57f..466a12b0c094 100644
@@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
 			       &iter->iomap, &iter->srcmap);
 	if (ret < 0)
 		return ret;
+	if (iter->iomap.length &&
+	    iter->iomap.offset + iter->iomap.length <= iter->pos) {
+		iter->iomap.flags |= IOMAP_F_STALE;
+		iomap_iter_reset_iomap(iter);
+		return 1;
+	}
+
 	iomap_iter_done(iter);
 	return 1;
 }
Signature · 1 line
2.34.1
#6 lore raw

PATCH 1/1 iomap: handle iterator position advancing beyond current mapping

In reply to Piyush Patle

iomap_iter_done() expects that the iterator position always lies within the current iomap range. However, during buffered writes combined with truncate or overwrite operations, the iterator position can advance past the end of the current iomap without the mapping being invalidated.

When this happens, iomap_iter_done() triggers a warning because iomap.offset + iomap.length no longer covers iter->pos, even though this state can legitimately occur due to extent invalidation or write completion advancing the iterator position.

Detect this condition immediately after iomap_begin(), mark the mapping as stale, reset the iterator state, and retry mapping from the current position. This ensures that iomap_end() invariants are preserved and prevents spurious warnings.

Fixes a66191c590b3b58eaff05d2277971f854772bd5b ("iomap: tighten iterator state validation")
Reported-by [email protected]
---
 fs/iomap/iter.c | 7 +++++++
 1 file changed, 7 insertions(+)
fs/iomap/iter.c +7 -0
index c04796f6e57f..466a12b0c094 100644
@@ -111,6 +111,13 @@ int iomap_iter(struct iomap_iter *iter, const struct iomap_ops *ops)
 			       &iter->iomap, &iter->srcmap);
 	if (ret < 0)
 		return ret;
+	if (iter->iomap.length &&
+	    iter->iomap.offset + iter->iomap.length <= iter->pos) {
+		iter->iomap.flags |= IOMAP_F_STALE;
+		iomap_iter_reset_iomap(iter);
+		return 1;
+	}
+
 	iomap_iter_done(iter);
 	return 1;
 }
Signature · 1 line
2.34.1