[PATCH 4/4] nvmet-auth: select the configured DH group from the host's list
Guixin Liu
kanie at linux.alibaba.com
Tue Dec 1 21:49:18 PST 2026
在 2026/12/2 12:01, sashiko-bot at kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 2 potential
> issues to consider:
> - [Critical] nvmet-auth: race and UAF in nvmet_auth_negotiate() via
> nvmet_setup_dhgroup()
Sashiko is right.
> - [High] nvmet-auth: NULL DH fallback in nvmet_auth_negotiate()
> downgrades FFDHE
Right, changed in v2.
> It also noticed 1 related pre-existing issue this patch does not
> introduce:
> - [Critical] nvmet-auth: missing dhvlen check in nvmet_auth_reply()
> bypasses DH exchange [1]
This is a pre-existing issue, I will take a look.
> --
>
> commit 9ae2d361be0af29223daffafb91f03e1b18c83ea
> Author: Guixin Liu <kanie at linux.alibaba.com>
>
> nvmet-auth: select the configured DH group from the host's list
>
> This commit updates DH group negotiation in nvmet_auth_negotiate() to match
> the configured DH group from the host's offered list or fall back to the
> first usable offered group and regenerate the DH context via
> nvmet_setup_dhgroup().
>
>> diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
>> index 34c2e14d0bd92..96765add5e4de 100644
>> --- a/drivers/nvme/target/fabrics-cmd-auth.c
>> +++ b/drivers/nvme/target/fabrics-cmd-auth.c
>> @@ -118,17 +118,21 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d, u32 tl)
>> fallback_dhgid = -1;
>> for (i = 0; i < data->auth_protocol[0].dhchap.dhlen; i++) {
>> int tmp_dhgid = data->auth_protocol[0].dhchap.idlist[i + 30];
>> + const char *kpp;
>>
>> - if (tmp_dhgid != ctrl->dh_gid) {
>> - dhgid = tmp_dhgid;
>> - break;
>> - }
>> if (fallback_dhgid < 0) {
>> - const char *kpp = nvme_auth_dhgroup_kpp(tmp_dhgid);
>> -
>> - if (crypto_has_kpp(kpp, 0, 0))
>> + if (tmp_dhgid == NVME_AUTH_DHGROUP_NULL) {
>> fallback_dhgid = tmp_dhgid;
>> + } else {
>> + kpp = nvme_auth_dhgroup_kpp(tmp_dhgid);
>> + if (kpp && crypto_has_kpp(kpp, 0, 0))
>> + fallback_dhgid = tmp_dhgid;
>> + }
>> }
> [Severity: High]
> Does accepting NVME_AUTH_DHGROUP_NULL as fallback_dhgid downgrade FFDHE
> negotiation to NULL DH?
>
> Fallback selection is only used when ctrl->dh_gid is a non-null FFDHE
> group that the host did not offer. Standard hosts such as the Linux
> NVMe host (nvme_auth_set_dhchap_negotiate_data()) put
> NVME_AUTH_DHGROUP_NULL in the first DH slot ahead of all FFDHE groups.
> Because fallback_dhgid latches onto 0 on the first entry, none of the
> subsequent FFDHE groups offered by the host are considered, and
> nvmet_setup_dhgroup(ctrl, NVME_AUTH_DHGROUP_NULL) tears down
> ctrl->dh_tfm and ctrl->dh_key. When ctrl->concat is enabled, latching
> onto NVME_AUTH_DHGROUP_NULL also causes negotiation to fail with
> NVME_AUTH_DHCHAP_FAILURE_CONCAT_MISMATCH even if valid FFDHE groups
> follow in idlist.
>
>> + if (tmp_dhgid != ctrl->dh_gid)
>> + continue;
>> + dhgid = tmp_dhgid;
>> + break;
>> }
>> if (dhgid < 0) {
>> if (fallback_dhgid < 0) {
>> @@ -139,7 +143,8 @@ static u8 nvmet_auth_negotiate(struct nvmet_req *req, void *d, u32 tl)
>> pr_debug("%s: ctrl %d qid %d: configured DH group %s not found\n",
>> __func__, ctrl->cntlid, req->sq->qid,
>> nvme_auth_dhgroup_name(fallback_dhgid));
>> - ctrl->dh_gid = fallback_dhgid;
>> + if (nvmet_setup_dhgroup(ctrl, fallback_dhgid) < 0)
>> + return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
>> }
>> if (ctrl->dh_gid == NVME_AUTH_DHGROUP_NULL && ctrl->concat) {
>> pr_debug("%s: ctrl %d qid %d: NULL DH group invalid "
> [Severity: Critical]
> Can calling nvmet_setup_dhgroup() here race across submission queues and
> corrupt ctrl->dh_tfm and ctrl->dh_key?
>
> nvmet_execute_auth_send() and nvmet_execute_auth_receive() can run
> concurrently on the admin queue and I/O queues while holding only the
> per-queue req->sq->auth_lock, whereas ctrl->dh_tfm, ctrl->dh_key,
> ctrl->dh_keysize and ctrl->dh_gid are shared across the controller:
>
> CPU0 (queue A) CPU1 (queue B)
> nvmet_execute_auth_receive()
> mutex_lock(&sqA->auth_lock)
> d = kzalloc(al, GFP_KERNEL)
> nvmet_auth_challenge()
> if (ctrl->dh_tfm)
> data_size += ctrl->dh_keysize;
> if (al < data_size) ...
> nvmet_execute_auth_send()
> mutex_lock(&sqB->auth_lock)
> nvmet_auth_negotiate()
> nvmet_setup_dhgroup(ctrl, ...)
> crypto_free_kpp(ctrl->dh_tfm)
> kfree_sensitive(ctrl->dh_key)
> ...
> ctrl->dh_keysize = 1024
> nvmet_auth_ctrl_exponential(...,
> ctrl->dh_keysize)
> memcpy(..., ctrl->dh_key, 1024) <-- heap buffer overflow / UAF
>
> Two queues can also call nvmet_setup_dhgroup() concurrently and double
> free ctrl->dh_tfm and ctrl->dh_key, or free ctrl->dh_tfm while another
> queue is using it in nvmet_auth_reply() -> nvmet_auth_ctrl_sesskey().
> In addition, because nvmet_execute_auth_send() only restores the
> controller's configured DH group via nvmet_setup_auth() when
> !req->sq->qid, a fallback on an I/O queue permanently changes or clears
> ctrl->dh_gid for the whole controller.
>
> [Severity: Critical]
> This problem wasn't introduced by this patch, but in nvmet_auth_reply()
> immediately below, can a reply with dhvlen == 0 bypass the negotiated
> Diffie-Hellman key exchange [1]?
>
> drivers/nvme/target/fabrics-cmd-auth.c:nvmet_auth_reply() {
> ...
> if (dhvlen) {
> if (!ctrl->dh_tfm)
> return NVME_AUTH_DHCHAP_FAILURE_INCORRECT_PAYLOAD;
> if (nvmet_auth_ctrl_sesskey(req, data->rval + 2 * data->hl,
> dhvlen) < 0)
> return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE;
> }
> ...
> }
>
> When a non-null DH group was negotiated (ctrl->dh_gid !=
> NVME_AUTH_DHGROUP_NULL and ctrl->dh_tfm != NULL), sending data->dhvlen
> set to 0 skips nvmet_auth_ctrl_sesskey(), leaving req->sq->dhchap_skey
> as NULL and req->sq->dhchap_skey_len as 0. nvmet_auth_host_hash() and
> nvmet_auth_ctrl_hash() then pass the empty session key to
> nvme_auth_augmented_challenge(), and when ctrl->concat is enabled,
> nvmet_auth_insert_psk() derives the TLS PSK with zero Diffie-Hellman
> entropy.
>
> [1] https://sashiko.dev/#/bug/linux-7531dbf0-44f0-49fe-9d48-917996e69355
>
More information about the Linux-nvme
mailing list