linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH V2] block: fix a mismatched alloc free in bio_alloc_bioset
@ 2019-08-19  0:55 Pan Bian
  2019-08-19  3:53 ` Ming Lei
  0 siblings, 1 reply; 2+ messages in thread
From: Pan Bian @ 2019-08-19  0:55 UTC (permalink / raw)
  To: Jens Axboe; +Cc: linux-block, linux-kernel, Pan Bian, stable

The function kmalloc is called to allocate memory if bs is NULL.
However, mempool_free is used to release the memory chunk even if bs is
NULL in the error hanlding code. This patch checks bs and use the
correct function to release memory.


Fixes: 3f86a82aeb ("block: Consolidate bio_alloc_bioset(), bio_kmalloc()")
Signed-off-by: Pan Bian <bianpan2016@163.com>
Cc: stable@vger.kernel.org
---
V2: add Fixes and Cc tags
---
 block/bio.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/block/bio.c b/block/bio.c
index 299a0e7..c5f5238 100644
--- a/block/bio.c
+++ b/block/bio.c
@@ -515,7 +515,10 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
 	return bio;
 
 err_free:
-	mempool_free(p, &bs->bio_pool);
+	if (!bs)
+		kfree(p);
+	else
+		mempool_free(p, &bs->bio_pool);
 	return NULL;
 }
 EXPORT_SYMBOL(bio_alloc_bioset);
-- 
2.7.4


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

* Re: [PATCH V2] block: fix a mismatched alloc free in bio_alloc_bioset
  2019-08-19  0:55 [PATCH V2] block: fix a mismatched alloc free in bio_alloc_bioset Pan Bian
@ 2019-08-19  3:53 ` Ming Lei
  0 siblings, 0 replies; 2+ messages in thread
From: Ming Lei @ 2019-08-19  3:53 UTC (permalink / raw)
  To: Pan Bian; +Cc: Jens Axboe, linux-block, linux-kernel, stable

On Mon, Aug 19, 2019 at 08:55:20AM +0800, Pan Bian wrote:
> The function kmalloc is called to allocate memory if bs is NULL.
> However, mempool_free is used to release the memory chunk even if bs is
> NULL in the error hanlding code. This patch checks bs and use the
> correct function to release memory.
> 
> 
> Fixes: 3f86a82aeb ("block: Consolidate bio_alloc_bioset(), bio_kmalloc()")
> Signed-off-by: Pan Bian <bianpan2016@163.com>
> Cc: stable@vger.kernel.org
> ---
> V2: add Fixes and Cc tags
> ---
>  block/bio.c | 5 ++++-
>  1 file changed, 4 insertions(+), 1 deletion(-)
> 
> diff --git a/block/bio.c b/block/bio.c
> index 299a0e7..c5f5238 100644
> --- a/block/bio.c
> +++ b/block/bio.c
> @@ -515,7 +515,10 @@ struct bio *bio_alloc_bioset(gfp_t gfp_mask, unsigned int nr_iovecs,
>  	return bio;
>  
>  err_free:
> -	mempool_free(p, &bs->bio_pool);
> +	if (!bs)
> +		kfree(p);
> +	else
> +		mempool_free(p, &bs->bio_pool);
>  	return NULL;
>  }
>  EXPORT_SYMBOL(bio_alloc_bioset);

'err_free' is only reached in case that 'bs' isn't NULL, so this patch
fixes nothing.


Thanks,
Ming

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

end of thread, other threads:[~2019-08-19  3:53 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-08-19  0:55 [PATCH V2] block: fix a mismatched alloc free in bio_alloc_bioset Pan Bian
2019-08-19  3:53 ` Ming Lei

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).