Skip to content

Commit dd8bbfe

Browse files
boryasgregkh
authored andcommitted
btrfs: check folio mapping after unlock in put_file_data()
commit 0fba7be upstream. 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: [email protected] # 6.12+ Reviewed-by: Qu Wenruo <[email protected]> Signed-off-by: Boris Burkov <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c3a403d commit dd8bbfe

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
@@ -5291,6 +5291,7 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
52915291
unsigned cur_len = min_t(unsigned, len,
52925292
PAGE_SIZE - pg_offset);
52935293

5294+
again:
52945295
folio = filemap_lock_folio(mapping, index);
52955296
if (IS_ERR(folio)) {
52965297
page_cache_sync_readahead(mapping,
@@ -5323,6 +5324,11 @@ static int put_file_data(struct send_ctx *sctx, u64 offset, u32 len)
53235324
ret = -EIO;
53245325
break;
53255326
}
5327+
if (folio->mapping != mapping) {
5328+
folio_unlock(folio);
5329+
folio_put(folio);
5330+
goto again;
5331+
}
53265332
}
53275333

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

0 commit comments

Comments
 (0)