lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <8a11ba5c-3836-0d95-7f70-7dc32bda95c1@interlog.com>
Date:   Mon, 13 Apr 2020 18:15:29 -0400
From:   Douglas Gilbert <dgilbert@...erlog.com>
To:     Li Bin <huawei.libin@...wei.com>, jejb@...ux.ibm.com,
        martin.petersen@...cle.com
Cc:     linux-scsi@...r.kernel.org, linux-kernel@...r.kernel.org,
        xiexiuqi@...wei.com
Subject: Re: [PATCH] scsi: sg: fix memory leak in sg_build_indirect

On 2020-04-13 7:32 a.m., Li Bin wrote:
> Fix a memory leak when there have failed, that we should free the pages
> under the condition rem_sz > 0.

May I paraphrase the above:
"Fix a memory leak that occurs when alloc_pages() succeeds several
  times before failing. This condition is noticed when rem_sz > 0."

> 
> Signed-off-by: Li Bin <huawei.libin@...wei.com>
> ---
>   drivers/scsi/sg.c | 6 +++++-
>   1 file changed, 5 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
> index 4e6af592..8441ac5 100644
> --- a/drivers/scsi/sg.c
> +++ b/drivers/scsi/sg.c
> @@ -1959,8 +1959,12 @@ static long sg_compat_ioctl(struct file *filp, unsigned int cmd_in, unsigned lon

It is the sg_build_indirect() function not sg_compat_ioctl() as suggested
above by git. Can be get a replacement for git :-)

>   			 k, rem_sz));
>   
>   	schp->bufflen = blk_size;
> -	if (rem_sz > 0)	/* must have failed */
> +	if (rem_sz > 0)	{ /* must have failed */
> +		for (i = 0; i < k; i++)
> +			__free_pages(schp->pages[i], order);
> +
>   		return -ENOMEM;

It is easier, and less code, to replace 'return -ENOMEM'; with
'goto out'. Or even simpler:

     if (likely(rem_sz == 0))
	return 0;
out:
      ........

Doug Gilbert


BTW I spotted this one during the sg driver rewrite and fixed it.
Note that this bug and several others like it won't be fixed by
me while the sg driver rewrite is pending.

> +	}
>   	return 0;
>   out:
>   	for (i = 0; i < k; i++)
> 

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ