From: Hannes Reinecke <hare@suse.de>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: linux-kernel@vger.kernel.org, kernel-janitors@vger.kernel.org,
linux-nvme@lists.infradead.org
Subject: Re: [PATCH] nvme-auth: Uninitialized variable in nvme_auth_transform_key()
Date: Fri, 22 Jul 2022 08:23:13 +0200 [thread overview]
Message-ID: <dfb1060c-d5fb-c375-848a-e9bcd2492f31@suse.de> (raw)
In-Reply-To: <YtU/tS/E2W9m+aau@kili>
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@oracle.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@suse.de>
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare@suse.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
next prev parent reply other threads:[~2022-07-22 6:23 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-18 11:09 [PATCH 1/2] nvme-auth: Fix off by one checks Dan Carpenter
2022-07-18 11:10 ` [PATCH] nvme-auth: Uninitialized variable in nvme_auth_transform_key() Dan Carpenter
2022-07-18 11:13 ` Dan Carpenter
2022-07-22 6:23 ` Hannes Reinecke [this message]
2022-07-22 4:48 ` [PATCH 1/2] nvme-auth: Fix off by one checks Christoph Hellwig
2022-07-22 6:22 ` Hannes Reinecke
2022-07-25 5:37 ` Christoph Hellwig
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=dfb1060c-d5fb-c375-848a-e9bcd2492f31@suse.de \
--to=hare@suse.de \
--cc=dan.carpenter@oracle.com \
--cc=kernel-janitors@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-nvme@lists.infradead.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