]> git.baikalelectronics.ru Git - kernel.git/commitdiff
block: fix memory leak of bvec
authorMing Lei <ming.lei@redhat.com>
Tue, 2 Feb 2021 15:54:10 +0000 (23:54 +0800)
committerJens Axboe <axboe@kernel.dk>
Tue, 2 Feb 2021 15:57:56 +0000 (08:57 -0700)
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: c41485517608 ("block: split bio_kmalloc from bio_alloc_bioset")
Cc: Johannes Thumshirn <johannes.thumshirn@wdc.com>
Cc: Chaitanya Kulkarni <chaitanya.kulkarni@wdc.com>
Cc: Damien Le Moal <damien.lemoal@wdc.com>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Ming Lei <ming.lei@redhat.com>
Signed-off-by: Jens Axboe <axboe@kernel.dk>
block/bio.c

index d4375619348c528b87c9b4eade2b977726d087c0..757fee46cefc791a0d867ad692939b391db611b0 100644 (file)
@@ -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 {