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] [thread-next>] [day] [month] [year] [list]
Message-ID: <20211104104727.GA3164@kadam>
Date:   Thu, 4 Nov 2021 13:47:27 +0300
From:   Dan Carpenter <dan.carpenter@...cle.com>
To:     George Kennedy <george.kennedy@...cle.com>
Cc:     gregkh@...uxfoundation.org, jejb@...ux.ibm.com,
        martin.petersen@...cle.com, linux-scsi@...r.kernel.org,
        linux-kernel@...r.kernel.org
Subject: Re: [PATCH] scsi: scsi_debug: fix return checks for kcalloc

This patch isn't right.  It has no effect on run time.

On Wed, Nov 03, 2021 at 02:01:42PM -0500, George Kennedy wrote:
> Change return checks from kcalloc() to now check for NULL and
> ZERO_SIZE_PTR using the ZERO_OR_NULL_PTR macro or the following
> crash can occur if ZERO_SIZE_PTR indicator is returned.

ZERO_SIZE_PTR is when you allocate a zero bytes successfully.  It's
quite useful because you can do:

	p = kmalloc(bytes, GFP_KERNEL);

	for (i = 0; i < bytes; i++)
		printk("%d\n", p[i]);

The for loop works.  Zero bytes now like normal thing instead of needing
to be handled as a special case.

The IS_ERR_OR_NULL() check treats ZERO_SIZE_PTR as a valid pointer.

> diff --git a/drivers/scsi/scsi_debug.c b/drivers/scsi/scsi_debug.c
> index 40b473e..222e985 100644
> --- a/drivers/scsi/scsi_debug.c
> +++ b/drivers/scsi/scsi_debug.c
> @@ -3909,7 +3909,7 @@ static int resp_comp_write(struct scsi_cmnd *scp,
>  		return ret;
>  	dnum = 2 * num;
>  	arr = kcalloc(lb_size, dnum, GFP_ATOMIC);
> -	if (NULL == arr) {
> +	if (ZERO_OR_NULL_PTR(arr)) {

kcalloc() only returns NULL on error.  This check is Yoda code but
besides the style issue it's fine.

>  		mk_sense_buffer(scp, ILLEGAL_REQUEST, INSUFF_RES_ASC,
>  				INSUFF_RES_ASCQ);
>  		return check_condition_result;
> @@ -4265,7 +4265,7 @@ static int resp_verify(struct scsi_cmnd *scp, struct sdebug_dev_info *devip)
>  		return ret;
>  
>  	arr = kcalloc(lb_size, vnum, GFP_ATOMIC);
> -	if (!arr) {

The rest of these are correct.  This patch doesn't fix a bug...

regards,
dan carpenter

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ