From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 4CE40606A31A for ; Wed, 2 Dec 2026 04:02:04 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=2yMXRSyq; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=Mv/yg/lX DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Reply-To:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Date: Content-Transfer-Encoding:Content-Type:References:In-Reply-To:Cc:To:Subject: From:Message-ID:MIME-Version:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Unsubscribe-Post:List-Owner; bh=YtwDz8LSfUR1qiR1WT5mN9T1iqjCwA+ZItOV4GGtzmc=; b=2yMXRSyqxkH9OCknS96cWZP5sf wWtjaStwlRWRToiyjKsQEMW45QsAQBgQEaa/FEYEaHTCS1B2Yq4kHAkmAgoddl8+teE2LJa2359NP NsIb6BttnJaLDhoC9NIqh5170Lj68I+NLqDtw7Oq2CmEkgk1iWCtP/zrWDr9Pl/c4X8OjIO+JCHsq AzCrK5KWAUnaRcRLfrEzJIVwdLwCnoOWsr44Nww5XQI5neGj1a77jAEUGLmWDc4H8796TNz7Qf1S5 B1muxMa7J+IiOzzbFjxBXs4Q82M7waRPy/Si6+SeUpfganVXM7LPvjQxuHuRYXk/NsPwHY5Fryy/w QvgMf1EQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYbXf-0000000A9oC-4Ama; Wed, 02 Dec 2026 04:02:03 +0000 Received: from sea.source.kernel.org ([172.234.252.31]) by bombadil.infradead.org with esmtps (Exim 4.100.1 #2 (Red Hat Linux)) id 1xYbXf-0000000A9o6-24fe for linux-nvme@lists.infradead.org; Wed, 02 Dec 2026 04:02:03 +0000 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) by sea.source.kernel.org (Postfix) with ESMTP id E421844E65; Wed, 2 Dec 2026 04:01:54 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id B4F071F00893; Wed, 2 Dec 2026 04:01:54 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796184114; bh=YtwDz8LSfUR1qiR1WT5mN9T1iqjCwA+ZItOV4GGtzmc=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=Mv/yg/lXK0PJIYqW2bSj8UrS9VuvLynX5gB1ijBnuucGbe6krHapCRog3CDfs8do9 bLYlEsD1j+zC5QIu05oeDFRtMfyWXvF3KxYFRWmZVNwgwFrFRqol3LZLXFBOzt+1F3 nBHpgbtg1mODSS6o0fu3nuiylUiBPtqa0ev2Cqo5ISWbNfOanFrhVg3EuucRvrlI3J 6bOYbT8GYhN1UyX1O2Jj39VSj1ViNqgRET8FUbYIKj1ATj04+o80jBzpUATpVGFQ+A cOddVuF2Pp3YEEjqmlhEp2tcqC2S7P1quAAsMhbhE/Co6qLJ+0fZnEUjMQqIKrtNKg USDF2Hq0koCYw== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list To: "Guixin Liu" Cc: linux-nvme@lists.infradead.org In-Reply-To: <20261202034707.3844378-5-kanie@linux.alibaba.com> References: <20261202034707.3844378-1-kanie@linux.alibaba.com> <20261202034707.3844378-5-kanie@linux.alibaba.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Wed, 02 Dec 2026 04:01:54 +0000 X-BeenThere: linux-nvme@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: sashiko-reviews@lists.linux.dev Sender: "Linux-nvme" X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=4.0.1 X-Spam-Checker-Version: SpamAssassin 4.0.1 (2024-03-26) on aws-us-west-2-korg-listserv-alma10-1 X-Archived-By: 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() - [High] nvmet-auth: NULL DH fallback in nvmet_auth_negotiate() downgrades FFDHE 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] -- commit 9ae2d361be0af29223daffafb91f03e1b18c83ea Author: Guixin Liu 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 *re= q, void *d, u32 tl) > fallback_dhgid =3D -1; > for (i =3D 0; i < data->auth_protocol[0].dhchap.dhlen; i++) { > int tmp_dhgid =3D data->auth_protocol[0].dhchap.idlist[i + 30]; > + const char *kpp; > =20 > - if (tmp_dhgid !=3D ctrl->dh_gid) { > - dhgid =3D tmp_dhgid; > - break; > - } > if (fallback_dhgid < 0) { > - const char *kpp =3D nvme_auth_dhgroup_kpp(tmp_dhgid); > - > - if (crypto_has_kpp(kpp, 0, 0)) > + if (tmp_dhgid =3D=3D NVME_AUTH_DHGROUP_NULL) { > fallback_dhgid =3D tmp_dhgid; > + } else { > + kpp =3D nvme_auth_dhgroup_kpp(tmp_dhgid); > + if (kpp && crypto_has_kpp(kpp, 0, 0)) > + fallback_dhgid =3D 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 !=3D ctrl->dh_gid) > + continue; > + dhgid =3D 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 =3D fallback_dhgid; > + if (nvmet_setup_dhgroup(ctrl, fallback_dhgid) < 0) > + return NVME_AUTH_DHCHAP_FAILURE_DHGROUP_UNUSABLE; > } > if (ctrl->dh_gid =3D=3D 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 =3D kzalloc(al, GFP_KERNEL) nvmet_auth_challenge() if (ctrl->dh_tfm) data_size +=3D 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 =3D 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 =3D=3D 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 !=3D NVME_AUTH_DHGROUP_NULL and ctrl->dh_tfm !=3D 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 --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261202034707.3844= 378-1-kanie@linux.alibaba.com?part=3D4