Skip to content

Commit 0fba7be

Browse files
boryaskdave
authored andcommitted
btrfs: check folio mapping after unlock in put_file_data()
When we call btrfs_read_folio() we get an unlocked folio, so it is possible for a different thread to concurrently modify folio->mapping. We must check that this hasn't happened once we do have the lock. CC: stable@vger.kernel.org # 6.12+ Reviewed-by: Qu Wenruo <wqu@suse.com> Signed-off-by: Boris Burkov <boris@bur.io> Signed-off-by: David Sterba <dsterba@suse.com>
1 parent 3e74859 commit 0fba7be

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

fs/btrfs/send.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5280,6 +5280,7 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
52805280
unsigned cur_len = min_t(unsigned, len,
52815281
PAGE_SIZE - pg_offset);
52825282

5283+
again:
52835284
folio = filemap_lock_folio(mapping, index);
52845285
if (IS_ERR(folio)) {
52855286
page_cache_sync_readahead(mapping,
@@ -5312,6 +5313,11 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
53125313
ret = -EIO;
53135314
break;
53145315
}
5316+
if (folio->mapping != mapping) {
5317+
folio_unlock(folio);
5318+
folio_put(folio);
5319+
goto again;
5320+
}
53155321
}
53165322

53175323
memcpy_from_folio(sctx->send_buf + sctx->send_size, folio,

0 commit comments

Comments
 (0)