Linux-HyperV List
 help / color / mirror / Atom feed
From: Tianyu Lan <ltykernel@gmail.com>
To: Juan Vazquez <juvazq@linux.microsoft.com>,
	kys@microsoft.com, haiyangz@microsoft.com,
	sthemmin@microsoft.com, wei.liu@kernel.org, decui@microsoft.com,
	mikelley@microsoft.com, jejb@linux.ibm.com,
	martin.petersen@oracle.com
Cc: linux-hyperv@vger.kernel.org, linux-scsi@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] scsi: storvsc: Fix storvsc_queuecommand() memory leak
Date: Mon, 10 Jan 2022 20:13:33 +0800	[thread overview]
Message-ID: <7354695e-a8dd-8c6c-ee7e-764280184863@gmail.com> (raw)
In-Reply-To: <20220109001758.6401-1-juvazq@linux.microsoft.com>

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 = {

  parent reply	other threads:[~2022-01-10 12:14 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 [this message]
2022-01-10 12:32   ` Wei Liu

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=7354695e-a8dd-8c6c-ee7e-764280184863@gmail.com \
    --to=ltykernel@gmail.com \
    --cc=decui@microsoft.com \
    --cc=haiyangz@microsoft.com \
    --cc=jejb@linux.ibm.com \
    --cc=juvazq@linux.microsoft.com \
    --cc=kys@microsoft.com \
    --cc=linux-hyperv@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=martin.petersen@oracle.com \
    --cc=mikelley@microsoft.com \
    --cc=sthemmin@microsoft.com \
    --cc=wei.liu@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox