[PATCH v6 5/9] nvmet-auth: parse dhchap key from configfs attribute
Hannes Reinecke
hare at suse.de
Mon Nov 23 23:55:24 PST 2026
On 11/23/26 6:30 PM, sashiko-bot at kernel.org wrote:
> 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)?
>
Fixed with the next version.
Cheers,
Hannes
--
Dr. Hannes Reinecke Kernel Storage Architect
hare at suse.de +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
More information about the Linux-nvme
mailing list