[PATCH v6 5/9] nvmet-auth: parse dhchap key from configfs attribute
sashiko-bot at kernel.org
sashiko-bot at kernel.org
Mon Nov 23 09:30:11 PST 2026
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmet-auth: host_key reference leak in nvmet_setup_auth() on
ctrl_key error
--
commit 0056af1c2f2c7d56f3cbd59406150e77070f9ffe
Author: Hannes Reinecke <hare at kernel.org>
nvmet-auth: parse dhchap key from configfs attribute
This commit converts the nvmet configfs DH-HMAC-CHAP key handling to
parse and store keys as struct key references on struct nvmet_host
instead of raw secret strings.
> diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
> index 26457ce4acc2a..6348c810bd168 100644
> --- a/drivers/nvme/target/auth.c
> +++ b/drivers/nvme/target/auth.c
[ ... ]
> @@ -186,22 +195,43 @@ u8 nvmet_setup_auth(struct nvmet_ctrl *ctrl, struct nvmet_sq *sq, bool reset)
> goto out_unlock;
> }
>
> - if (!host->dhchap_secret) {
> + if (!host->dhchap_key) {
> pr_debug("No authentication provided\n");
> goto out_unlock;
> }
>
> - host_key = nvme_auth_extract_key(NULL, host->dhchap_secret,
> - strlen(host->dhchap_secret));
> - if (IS_ERR(host_key)) {
> + host_key = key_get(host->dhchap_key);
> + if (!host_key) {
> + pr_warn("%s: host key %08x not found\n",
> + __func__, key_serial(host->dhchap_key));
> ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
> goto out_unlock;
> }
> - if (host->dhchap_ctrl_secret) {
> - ctrl_key = nvme_auth_extract_key(NULL, host->dhchap_ctrl_secret,
> - strlen(host->dhchap_ctrl_secret));
> - if (IS_ERR(ctrl_key)) {
> - key_put(host_key);
> + down_read(&host_key->sem);
> + ret = key_validate(host_key);
> + key_id = key_serial(host_key);
> + up_read(&host_key->sem);
> + if (ret) {
> + pr_warn("host key %08x invalidated\n", key_id);
> + key_put(host_key);
> + ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
> + goto out_unlock;
> + }
> + if (host->dhchap_ctrl_key) {
> + ctrl_key = key_get(host->dhchap_ctrl_key);
> + if (!ctrl_key) {
> + pr_warn("%s: ctrl key %08x not found\n",
> + __func__, key_serial(host->dhchap_ctrl_key));
> + ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
> + goto out_unlock;
> + }
> + down_read(&ctrl_key->sem);
> + ret = key_validate(ctrl_key);
> + key_id = key_serial(ctrl_key);
> + up_read(&ctrl_key->sem);
> + if (ret) {
> + pr_warn("ctrl key %08x invalidated\n", key_id);
> + key_put(ctrl_key);
> ret = NVME_AUTH_DHCHAP_FAILURE_NOT_USABLE;
> goto out_unlock;
> }
[Severity: Medium]
Do both error paths under if (host->dhchap_ctrl_key) leak host_key by
jumping to out_unlock without calling key_put(host_key)?
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261123-dhchap-keyring-v4-v6-0-5082a49715ab@kernel.org?part=5
More information about the Linux-nvme
mailing list