Skip to content

Commit 26899ca

Browse files
Liu Bogregkh
Liu Bo
authored andcommitted
Btrfs: fix potential use-after-free for cloned bio
[ Upstream commit a967efb ] KASAN reports that there is a use-after-free case of bio in btrfs_map_bio. If we need to submit IOs to several disks at a time, the original bio would get cloned and mapped to the destination disk, but we really should use the original bio instead of a cloned bio to do the sanity check because cloned bios are likely to be freed by its endio. Reported-by: Diego <[email protected]> Signed-off-by: Liu Bo <[email protected]> Reviewed-by: David Sterba <[email protected]> Signed-off-by: David Sterba <[email protected]> Signed-off-by: Sasha Levin <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent c17acd2 commit 26899ca

File tree

1 file changed

+1
-1
lines changed

1 file changed

+1
-1
lines changed

fs/btrfs/volumes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6226,7 +6226,7 @@ int btrfs_map_bio(struct btrfs_root *root, struct bio *bio,
62266226
for (dev_nr = 0; dev_nr < total_devs; dev_nr++) {
62276227
dev = bbio->stripes[dev_nr].dev;
62286228
if (!dev || !dev->bdev ||
6229-
(bio_op(bio) == REQ_OP_WRITE && !dev->writeable)) {
6229+
(bio_op(first_bio) == REQ_OP_WRITE && !dev->writeable)) {
62306230
bbio_error(bbio, first_bio, logical);
62316231
continue;
62326232
}

0 commit comments

Comments
 (0)