Linux-NVME Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
To: "Sreeraj S Kurup" <sreekuttan2156239@gmail.com>
Cc: linux-nvme@lists.infradead.org
Subject: Re: [PATCH v2] nvmet: clean up DH group state on initialization failure
Date: Tue, 10 Nov 2026 09:39:01 +0000	[thread overview]
Message-ID: <sashiko-outbox-206787@kernel.org> (raw)
In-Reply-To: <20261110093047.4290-1-sreekuttan2156239@gmail.com>

Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [High] nvmet: nvmet_setup_dhgroup() returns 0 when crypto_alloc_kpp()
  fails
--

commit a615cbc77d9efc8d40fbde68d3ff3d83eaa208bd
Author: Sreeraj S Kurup <sreekuttan2156239@gmail.com>

nvmet: clean up DH group state on initialization failure

This commit adds a shared error label in nvmet_setup_dhgroup() to free
ctrl->dh_tfm and reset DH group state when private-key generation,
public-key allocation, or public-key generation fails.

> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
> index ccba84b1344e0..20f8c84e8ced5 100644
> --- a/drivers/nvme/target/auth.c
> +++ b/drivers/nvme/target/auth.c
> @@ -105,9 +105,7 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
>  		if (ret < 0) {
>  			pr_debug("%s: ctrl %d failed to generate private key, err %d\n",
>  				 __func__, ctrl->cntlid, ret);
> -			kfree_sensitive(ctrl->dh_key);
> -			ctrl->dh_key = NULL;
> -			return ret;
> +			goto err;
>  		}
>  		ctrl->dh_keysize = crypto_kpp_maxsize(ctrl->dh_tfm);
>  		kfree_sensitive(ctrl->dh_key);
> @@ -115,18 +113,26 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
>  		if (!ctrl->dh_key) {
>  			pr_warn("ctrl %d failed to allocate public key\n",
>  				ctrl->cntlid);
> -			return -ENOMEM;
> +			ret = -ENOMEM;
> +			goto err;
>  		}
>  		ret = nvme_auth_gen_pubkey(ctrl->dh_tfm, ctrl->dh_key,
>  					   ctrl->dh_keysize);
>  		if (ret < 0) {
>  			pr_warn("ctrl %d failed to generate public key\n",
>  				ctrl->cntlid);
> -			kfree(ctrl->dh_key);
> -			ctrl->dh_key = NULL;
> +			goto err;
>  		}
>  	}
>  
> +	return 0;
> +err:
> +	kfree_sensitive(ctrl->dh_key);
> +	ctrl->dh_key = NULL;
> +	crypto_free_kpp(ctrl->dh_tfm);
> +	ctrl->dh_tfm = NULL;
> +	ctrl->dh_gid = 0;
> +	ctrl->dh_keysize = 0;
>  	return ret;
>  }

[Severity: High]
Does nvmet_setup_dhgroup() now return 0 when crypto_alloc_kpp() fails?

drivers/nvme/target/auth.c:nvmet_setup_dhgroup() {
	...
	ctrl->dh_tfm = crypto_alloc_kpp(dhgroup_kpp, 0, 0);
	if (IS_ERR(ctrl->dh_tfm)) {
		...
		ret = PTR_ERR(ctrl->dh_tfm);
		ctrl->dh_tfm = NULL;
		ctrl->dh_gid = 0;
	} else {
	...
}

The IS_ERR(ctrl->dh_tfm) branch previously fell through the end of the
if-else block to "return ret;".  With "return 0;" placed right before
err, a crypto_alloc_kpp() failure falls through and reports success to
nvmet_setup_auth(), silently proceeding with ctrl->dh_tfm set to NULL and
ctrl->dh_gid set to NVME_AUTH_DHGROUP_NULL instead of failing with
NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE, and leaving any prior
ctrl->dh_key and ctrl->dh_keysize in place on re-authentication.

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261110093047.4290-1-sreekuttan2156239@gmail.com?part=1


      reply	other threads:[~2026-11-10  9:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-10  9:30 [PATCH v2] nvmet: clean up DH group state on initialization failure Sreeraj S Kurup
2026-11-10  9:39 ` sashiko-bot [this message]

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=sashiko-outbox-206787@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-nvme@lists.infradead.org \
    --cc=sashiko-reviews@lists.linux.dev \
    --cc=sreekuttan2156239@gmail.com \
    /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