diff mbox series

block: fix memory leak of bvec

Message ID 20210202155410.875745-1-ming.lei@redhat.com (mailing list archive)
State New, archived
Headers show
Series block: fix memory leak of bvec | expand

Commit Message

Ming Lei Feb. 2, 2021, 3:54 p.m. UTC
bio_init() clears bio instance, so the bvec index has to be set after
bio_init(), otherwise bio->bi_io_vec may be leaked.

Fixes: 3175199ab0ac ("block: split bio_kmalloc from bio_alloc_bioset")
Cc: Christoph Hellwig <hch@lst.de>
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Cc: Damien Le Moal <damien.lemoal@wdc.com>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
---
 block/bio.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Christoph Hellwig Feb. 2, 2021, 3:55 p.m. UTC | #1
On Tue, Feb 02, 2021 at 11:54:10PM +0800, Ming Lei wrote:
> bio_init() clears bio instance, so the bvec index has to be set after
> bio_init(), otherwise bio->bi_io_vec may be leaked.

Yeah, I've got exactly the same test sitting here as part of a larger
series:

Reviewed-by: Christoph Hellwig <hch@lst.de>
Jens Axboe Feb. 2, 2021, 3:58 p.m. UTC | #2
On 2/2/21 8:54 AM, Ming Lei wrote:
> bio_init() clears bio instance, so the bvec index has to be set after
> bio_init(), otherwise bio->bi_io_vec may be leaked.

Applied, thanks.
diff mbox series

Patch

diff --git a/block/bio.c b/block/bio.c
index d4375619348c..757fee46cefc 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -482,8 +482,8 @@  struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
 		if (unlikely(!bvl))
 			goto err_free;
 
-		bio->bi_flags |= idx << BVEC_POOL_OFFSET;
 		bio_init(bio, bvl, bvec_nr_vecs(idx));
+		bio->bi_flags |= idx << BVEC_POOL_OFFSET;
 	} else if (nr_iovecs) {
 		bio_init(bio, bio->bi_inline_vecs, BIO_INLINE_VECS);
 	} else {