All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] block: fix use-after-free in disk_part_iter_next
@ 2020-12-21  4:33 Ming Lei
  2021-01-05  7:51 ` Christoph Hellwig
  2021-01-05 18:35 ` Jens Axboe
  0 siblings, 2 replies; 3+ messages in thread
From: Ming Lei @ 2020-12-21  4:33 UTC (permalink / raw)
  To: Jens Axboe
  Cc: linux-block, Christoph Hellwig, Ming Lei, stable,
	syzbot+825f0f9657d4e528046e

Make sure that bdgrab() is done on the 'block_device' instance before
referring to it for avoiding use-after-free.

Cc: <stable@vger.kernel.org>
Reported-by: syzbot+825f0f9657d4e528046e@syzkaller.appspotmail.com
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/genhd.c | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/block/genhd.c b/block/genhd.c
index b84b8671e627..2df3c5b1c9c8 100644
--- a/block/genhd.c
+++ b/block/genhd.c
@@ -244,15 +244,18 @@ struct block_device *disk_part_iter_next(struct disk_part_iter *piter)
 		part = rcu_dereference(ptbl->part[piter->idx]);
 		if (!part)
 			continue;
+		piter->part = bdgrab(part);
+		if (!piter->part)
+			continue;
 		if (!bdev_nr_sectors(part) &&
 		    !(piter->flags & DISK_PITER_INCL_EMPTY) &&
 		    !(piter->flags & DISK_PITER_INCL_EMPTY_PART0 &&
-		      piter->idx == 0))
+		      piter->idx == 0)) {
+			bdput(piter->part);
+			piter->part = NULL;
 			continue;
+		}
 
-		piter->part = bdgrab(part);
-		if (!piter->part)
-			continue;
 		piter->idx += inc;
 		break;
 	}
-- 
2.28.0


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

* Re: [PATCH] block: fix use-after-free in disk_part_iter_next
  2020-12-21  4:33 [PATCH] block: fix use-after-free in disk_part_iter_next Ming Lei
@ 2021-01-05  7:51 ` Christoph Hellwig
  2021-01-05 18:35 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2021-01-05  7:51 UTC (permalink / raw)
  To: Ming Lei
  Cc: Jens Axboe, linux-block, Christoph Hellwig, stable,
	syzbot+825f0f9657d4e528046e

On Mon, Dec 21, 2020 at 12:33:35PM +0800, Ming Lei wrote:
> Make sure that bdgrab() is done on the 'block_device' instance before
> referring to it for avoiding use-after-free.
> 
> Cc: <stable@vger.kernel.org>
> Reported-by: syzbot+825f0f9657d4e528046e@syzkaller.appspotmail.com
> Signed-off-by: Ming Lei <ming.lei@redhat.com>

Looks good,

Reviewed-by: Christoph Hellwig <hch@lst.de>

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

* Re: [PATCH] block: fix use-after-free in disk_part_iter_next
  2020-12-21  4:33 [PATCH] block: fix use-after-free in disk_part_iter_next Ming Lei
  2021-01-05  7:51 ` Christoph Hellwig
@ 2021-01-05 18:35 ` Jens Axboe
  1 sibling, 0 replies; 3+ messages in thread
From: Jens Axboe @ 2021-01-05 18:35 UTC (permalink / raw)
  To: Ming Lei
  Cc: linux-block, Christoph Hellwig, stable, syzbot+825f0f9657d4e528046e

On 12/20/20 9:33 PM, Ming Lei wrote:
> Make sure that bdgrab() is done on the 'block_device' instance before
> referring to it for avoiding use-after-free.

Applied, thanks.

-- 
Jens Axboe


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

end of thread, other threads:[~2021-01-05 18:36 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-21  4:33 [PATCH] block: fix use-after-free in disk_part_iter_next Ming Lei
2021-01-05  7:51 ` Christoph Hellwig
2021-01-05 18:35 ` Jens Axboe

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.