Skip to content

Commit 389f239

Browse files
committed
btrfs: make sure we stay inside the bvec during __btrfs_lookup_bio_sums
Commit c40a3d3 (Btrfs: Compute and look up csums based on sectorsized blocks) changes around how we walk the bios while looking up crcs. There's an inner loop that is jumping to the next bvec based on sectors and before it derefs the next bvec, it needs to make sure we're still in the bio. In this case, the outer loop would have decided to stop moving forward too, and the bvec deref is never actually used for anything. But CONFIG_DEBUG_PAGEALLOC catches it because we're outside our bio. Signed-off-by: Chris Mason <clm@fb.com> Reviewed-by: David Sterba <dsterba@suse.com>
1 parent bb7ab3b commit 389f239

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

fs/btrfs/file-item.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,12 +292,22 @@ static int __btrfs_lookup_bio_sums(struct btrfs_root *root,
292292
page_bytes_left -= root->sectorsize;
293293
if (!page_bytes_left) {
294294
bio_index++;
295+
/*
296+
* make sure we're still inside the
297+
* bio before we update page_bytes_left
298+
*/
299+
if (bio_index >= bio->bi_vcnt) {
300+
WARN_ON_ONCE(count);
301+
goto done;
302+
}
295303
bvec++;
296304
page_bytes_left = bvec->bv_len;
297305
}
298306

299307
}
300308
}
309+
310+
done:
301311
btrfs_free_path(path);
302312
return 0;
303313
}

0 commit comments

Comments
 (0)