All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] Btrfs: fix potential use-after-free for cloned bio
@ 2017-04-10 19:36 Liu Bo
  2017-04-11 11:47 ` David Sterba
  0 siblings, 1 reply; 2+ messages in thread
From: Liu Bo @ 2017-04-10 19:36 UTC (permalink / raw)
  To: linux-btrfs

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 <diegocg@gmail.com>
Signed-off-by: Liu Bo <bo.li.liu@oracle.com>
---
 fs/btrfs/volumes.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c
index 73d56ee..ab8a66d 100644
--- a/fs/btrfs/volumes.c
+++ b/fs/btrfs/volumes.c
@@ -6213,7 +6213,7 @@ int btrfs_map_bio(struct btrfs_fs_info *fs_info, struct bio *bio,
 	for (dev_nr = 0; dev_nr < total_devs; dev_nr++) {
 		dev = bbio->stripes[dev_nr].dev;
 		if (!dev || !dev->bdev ||
-		    (bio_op(bio) == REQ_OP_WRITE && !dev->writeable)) {
+		    (bio_op(first_bio) == REQ_OP_WRITE && !dev->writeable)) {
 			bbio_error(bbio, first_bio, logical);
 			continue;
 		}
-- 
2.5.5


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] Btrfs: fix potential use-after-free for cloned bio
  2017-04-10 19:36 [PATCH] Btrfs: fix potential use-after-free for cloned bio Liu Bo
@ 2017-04-11 11:47 ` David Sterba
  0 siblings, 0 replies; 2+ messages in thread
From: David Sterba @ 2017-04-11 11:47 UTC (permalink / raw)
  To: Liu Bo; +Cc: linux-btrfs

On Mon, Apr 10, 2017 at 12:36:26PM -0700, Liu Bo wrote:
> 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 <diegocg@gmail.com>
> Signed-off-by: Liu Bo <bo.li.liu@oracle.com>

Reviewed-by: David Sterba <dsterba@suse.com>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-04-11 11:47 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10 19:36 [PATCH] Btrfs: fix potential use-after-free for cloned bio Liu Bo
2017-04-11 11:47 ` David Sterba

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.