linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak
@ 2022-01-09  0:17 Juan Vazquez
  2022-01-10 11:56 ` Wei Liu
  2022-01-10 12:13 ` Tianyu Lan
  0 siblings, 2 replies; 4+ messages in thread
From: Juan Vazquez @ 2022-01-09  0:17 UTC (permalink / raw)
  To: kys, haiyangz, sthemmin, wei.liu, decui, mikelley, jejb, martin.petersen
  Cc: linux-hyperv, linux-scsi, linux-kernel

Fix possible memory leak in error path of storvsc_queuecommand() when
DMA mapping fails.

Fixes: 743b237c3a7b ("scsi: storvsc: Add Isolation VM support for storvsc driver")
Signed-off-by: Juan Vazquez <juvazq@linux.microsoft.com>
---
 drivers/scsi/storvsc_drv.c | 17 ++++++++++++-----
 1 file changed, 12 insertions(+), 5 deletions(-)

diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
index 2273b843d9d2..9a0bba5a51a7 100644
--- a/drivers/scsi/storvsc_drv.c
+++ b/drivers/scsi/storvsc_drv.c
@@ -1850,8 +1850,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
 		payload->range.offset = offset_in_hvpg;
 
 		sg_count = scsi_dma_map(scmnd);
-		if (sg_count < 0)
-			return SCSI_MLQUEUE_DEVICE_BUSY;
+		if (sg_count < 0) {
+			ret = SCSI_MLQUEUE_DEVICE_BUSY;
+			goto err_free_payload;
+		}
 
 		for_each_sg(sgl, sg, sg_count, j) {
 			/*
@@ -1886,13 +1888,18 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
 	put_cpu();
 
 	if (ret == -EAGAIN) {
-		if (payload_sz > sizeof(cmd_request->mpb))
-			kfree(payload);
 		/* no more space */
-		return SCSI_MLQUEUE_DEVICE_BUSY;
+		ret = SCSI_MLQUEUE_DEVICE_BUSY;
+		goto err_free_payload;
 	}
 
 	return 0;
+
+err_free_payload:
+	if (payload_sz > sizeof(cmd_request->mpb))
+		kfree(payload);
+
+	return ret;
 }
 
 static struct scsi_host_template scsi_driver = {
-- 
2.32.0


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

* Re: [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak
  2022-01-09  0:17 [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak Juan Vazquez
@ 2022-01-10 11:56 ` Wei Liu
  2022-01-10 12:13 ` Tianyu Lan
  1 sibling, 0 replies; 4+ messages in thread
From: Wei Liu @ 2022-01-10 11:56 UTC (permalink / raw)
  To: Juan Vazquez
  Cc: kys, haiyangz, sthemmin, wei.liu, decui, mikelley, jejb,
	martin.petersen, linux-hyperv, linux-scsi, linux-kernel,
	tianyu.lan, longli

On Sat, Jan 08, 2022 at 04:17:58PM -0800, Juan Vazquez wrote:
> Fix possible memory leak in error path of storvsc_queuecommand() when
> DMA mapping fails.
> 
> Fixes: 743b237c3a7b ("scsi: storvsc: Add Isolation VM support for storvsc driver")
> Signed-off-by: Juan Vazquez <juvazq@linux.microsoft.com>

Martin, I can pick this up since the offending commit is not yet in
Linus' tree.

Tianyu, Long and Michael, the change makes sense to me but can you give
an ack or review here?

> ---
>  drivers/scsi/storvsc_drv.c | 17 ++++++++++++-----
>  1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
> index 2273b843d9d2..9a0bba5a51a7 100644
> --- a/drivers/scsi/storvsc_drv.c
> +++ b/drivers/scsi/storvsc_drv.c
> @@ -1850,8 +1850,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
>  		payload->range.offset = offset_in_hvpg;
>  
>  		sg_count = scsi_dma_map(scmnd);
> -		if (sg_count < 0)
> -			return SCSI_MLQUEUE_DEVICE_BUSY;
> +		if (sg_count < 0) {
> +			ret = SCSI_MLQUEUE_DEVICE_BUSY;
> +			goto err_free_payload;
> +		}
>  
>  		for_each_sg(sgl, sg, sg_count, j) {
>  			/*
> @@ -1886,13 +1888,18 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
>  	put_cpu();
>  
>  	if (ret == -EAGAIN) {
> -		if (payload_sz > sizeof(cmd_request->mpb))
> -			kfree(payload);
>  		/* no more space */
> -		return SCSI_MLQUEUE_DEVICE_BUSY;
> +		ret = SCSI_MLQUEUE_DEVICE_BUSY;
> +		goto err_free_payload;
>  	}
>  
>  	return 0;
> +
> +err_free_payload:
> +	if (payload_sz > sizeof(cmd_request->mpb))
> +		kfree(payload);
> +
> +	return ret;
>  }
>  
>  static struct scsi_host_template scsi_driver = {
> -- 
> 2.32.0
> 

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

* Re: [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak
  2022-01-09  0:17 [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak Juan Vazquez
  2022-01-10 11:56 ` Wei Liu
@ 2022-01-10 12:13 ` Tianyu Lan
  2022-01-10 12:32   ` Wei Liu
  1 sibling, 1 reply; 4+ messages in thread
From: Tianyu Lan @ 2022-01-10 12:13 UTC (permalink / raw)
  To: Juan Vazquez, kys, haiyangz, sthemmin, wei.liu, decui, mikelley,
	jejb, martin.petersen
  Cc: linux-hyperv, linux-scsi, linux-kernel

On 1/9/2022 8:17 AM, Juan Vazquez wrote:
> Fix possible memory leak in error path of storvsc_queuecommand() when
> DMA mapping fails.
> 
> Fixes: 743b237c3a7b ("scsi: storvsc: Add Isolation VM support for storvsc driver")
> Signed-off-by: Juan Vazquez <juvazq@linux.microsoft.com>

Looks good. Thanks for the fix patch.

Reviewed-by: Tianyu Lan <Tianyu.Lan@microsoft.com>

> ---
>   drivers/scsi/storvsc_drv.c | 17 ++++++++++++-----
>   1 file changed, 12 insertions(+), 5 deletions(-)
> 
> diff --git a/drivers/scsi/storvsc_drv.c b/drivers/scsi/storvsc_drv.c
> index 2273b843d9d2..9a0bba5a51a7 100644
> --- a/drivers/scsi/storvsc_drv.c
> +++ b/drivers/scsi/storvsc_drv.c
> @@ -1850,8 +1850,10 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
>   		payload->range.offset = offset_in_hvpg;
>   
>   		sg_count = scsi_dma_map(scmnd);
> -		if (sg_count < 0)
> -			return SCSI_MLQUEUE_DEVICE_BUSY;
> +		if (sg_count < 0) {
> +			ret = SCSI_MLQUEUE_DEVICE_BUSY;
> +			goto err_free_payload;
> +		}
>   
>   		for_each_sg(sgl, sg, sg_count, j) {
>   			/*
> @@ -1886,13 +1888,18 @@ static int storvsc_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *scmnd)
>   	put_cpu();
>   
>   	if (ret == -EAGAIN) {
> -		if (payload_sz > sizeof(cmd_request->mpb))
> -			kfree(payload);
>   		/* no more space */
> -		return SCSI_MLQUEUE_DEVICE_BUSY;
> +		ret = SCSI_MLQUEUE_DEVICE_BUSY;
> +		goto err_free_payload;
>   	}
>   
>   	return 0;
> +
> +err_free_payload:
> +	if (payload_sz > sizeof(cmd_request->mpb))
> +		kfree(payload);
> +
> +	return ret;
>   }
>   
>   static struct scsi_host_template scsi_driver = {

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

* Re: [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak
  2022-01-10 12:13 ` Tianyu Lan
@ 2022-01-10 12:32   ` Wei Liu
  0 siblings, 0 replies; 4+ messages in thread
From: Wei Liu @ 2022-01-10 12:32 UTC (permalink / raw)
  To: Tianyu Lan
  Cc: Juan Vazquez, kys, haiyangz, sthemmin, wei.liu, decui, mikelley,
	jejb, martin.petersen, linux-hyperv, linux-scsi, linux-kernel

On Mon, Jan 10, 2022 at 08:13:33PM +0800, Tianyu Lan wrote:
> On 1/9/2022 8:17 AM, Juan Vazquez wrote:
> > Fix possible memory leak in error path of storvsc_queuecommand() when
> > DMA mapping fails.
> > 
> > Fixes: 743b237c3a7b ("scsi: storvsc: Add Isolation VM support for storvsc driver")
> > Signed-off-by: Juan Vazquez <juvazq@linux.microsoft.com>
> 
> Looks good. Thanks for the fix patch.
> 
> Reviewed-by: Tianyu Lan <Tianyu.Lan@microsoft.com>

Applied. Thanks.

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

end of thread, other threads:[~2022-01-10 12:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-09  0:17 [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak Juan Vazquez
2022-01-10 11:56 ` Wei Liu
2022-01-10 12:13 ` Tianyu Lan
2022-01-10 12:32   ` Wei Liu

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).