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: <dfb1060c-d5fb-c375-848a-e9bcd2492f31@suse.de>
Date:   Fri, 22 Jul 2022 08:23:13 +0200
From:   Hannes Reinecke <hare@...e.de>
To:     Dan Carpenter <dan.carpenter@...cle.com>
Cc:     linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
        linux-nvme@...ts.infradead.org
Subject: Re: [PATCH] nvme-auth: Uninitialized variable in
 nvme_auth_transform_key()

On 7/18/22 13:10, Dan Carpenter wrote:
> A couple of the early error gotos call kfree_sensitive(transformed_key);
> before "transformed_key" has been initialized.
> 
> Fixes: a476416bb57b ("nvme: implement In-Band authentication")
> Signed-off-by: Dan Carpenter <dan.carpenter@...cle.com>
> ---
> I wrote this several times in different ways, and kept on doing it
> wrong so in the end I wrote it this way.  It's a bigger diff, but I
> think it's the clearest way to write it.
> 
>   drivers/nvme/common/auth.c | 25 ++++++++++++++++---------
>   1 file changed, 16 insertions(+), 9 deletions(-)
> 
> diff --git a/drivers/nvme/common/auth.c b/drivers/nvme/common/auth.c
> index bfb16fec0aed..1890193c7333 100644
> --- a/drivers/nvme/common/auth.c
> +++ b/drivers/nvme/common/auth.c
> @@ -278,26 +278,33 @@ u8 *nvme_auth_transform_key(struct nvme_dhchap_key *key, char *nqn)
>   	shash->tfm = key_tfm;
>   	ret = crypto_shash_setkey(key_tfm, key->key, key->len);
>   	if (ret < 0)
> -		goto out_free_shash;
> +		goto out_free_transformed_key;
>   	ret = crypto_shash_init(shash);
>   	if (ret < 0)
> -		goto out_free_shash;
> +		goto out_free_transformed_key;
>   	ret = crypto_shash_update(shash, nqn, strlen(nqn));
>   	if (ret < 0)
> -		goto out_free_shash;
> +		goto out_free_transformed_key;
>   	ret = crypto_shash_update(shash, "NVMe-over-Fabrics", 17);
>   	if (ret < 0)
> -		goto out_free_shash;
> +		goto out_free_transformed_key;
>   	ret = crypto_shash_final(shash, transformed_key);
> +	if (ret < 0)
> +		goto out_free_transformed_key;
> +
> +	kfree(shash);
> +	crypto_free_shash(key_tfm);
> +
> +	return transformed_key;
> +
> +out_free_transformed_key:
> +	kfree_sensitive(transformed_key);
>   out_free_shash:
>   	kfree(shash);
>   out_free_key:
>   	crypto_free_shash(key_tfm);
> -	if (ret < 0) {
> -		kfree_sensitive(transformed_key);
> -		return ERR_PTR(ret);
> -	}
> -	return transformed_key;
> +
> +	return ERR_PTR(ret);
>   }
>   EXPORT_SYMBOL_GPL(nvme_auth_transform_key);
>   
Reviewed-by: Hannes Reinecke <hare@...e.de>

Cheers,

Hannes
-- 
Dr. Hannes Reinecke                Kernel Storage Architect
hare@...e.de                              +49 911 74053 688
SUSE Software Solutions GmbH, Maxfeldstr. 5, 90409 Nürnberg
HRB 36809 (AG Nürnberg), Geschäftsführer: Ivo Totev, Andrew
Myers, Andrew McDonald, Martje Boudien Moerman

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ