* [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit
@ 2026-12-02 3:47 Guixin Liu
2026-12-02 3:47 ` [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent Guixin Liu
` (3 more replies)
0 siblings, 4 replies; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 3:47 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
A static audit of drivers/nvme turned up these four independent bugs.
Each patch has its own reproducer and regression run, described below
the --- line.
nvme: mask the status before checking for Host Identifier Inconsistent
The EDS->legacy reservation report fallback never triggers when the
controller sets DNR.
nvmet: read CRTO from the capability register
The CRTO property is extracted from CSTS and always reads zero.
nvmet: snapshot the passthru command before completing the request
nvme_passthru_end() reads req->cmd after the loop host request has
been freed.
nvmet-auth: select the configured DH group from the host's list
DH group negotiation keeps a group the host did not offer and the
fallback is dead logic.
Testing: QEMU/KVM guest, 7.3.0 kernel with KASAN, nvmet-tcp, nvme-loop
and nvmet passthru to a QEMU nvme backend. Each fix was reproduced on
the unpatched code, verified with the same recipe after patching, and
regression-tested with the test-only injections removed. The
passthru use-after-free is evidenced by free/read address tracking; the
test kernel's module-side KASAN does not splat on that access, as noted
in patch 3. The test-only injections live in the test environment only,
not in these patches.
Guixin Liu (4):
nvme: mask the status before checking for Host Identifier Inconsistent
nvmet: read CRTO from the capability register
nvmet: snapshot the passthru command before completing the request
nvmet-auth: select the configured DH group from the host's list
drivers/nvme/host/pr.c | 2 +-
drivers/nvme/target/fabrics-cmd-auth.c | 21 +++++++++++++--------
drivers/nvme/target/fabrics-cmd.c | 2 +-
drivers/nvme/target/passthru.c | 10 +++++++++-
4 files changed, 24 insertions(+), 11 deletions(-)
--
2.43.7
^ permalink raw reply [flat|nested] 9+ messages in thread
* [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent
2026-12-02 3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
@ 2026-12-02 3:47 ` Guixin Liu
2026-12-02 3:47 ` [PATCH 2/4] nvmet: read CRTO from the capability register Guixin Liu
` (2 subsequent siblings)
3 siblings, 0 replies; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 3:47 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
nvme_pr_resv_report() retries with the legacy data structure when the
controller returns Host Identifier Inconsistent, but compares the raw
status returned by nvme_execute_rq(). A controller that sets the DNR
bit on that status never matches, so the fallback never happens and
the reservation report fails against such controllers.
Mask the status with NVME_SCT_SC_MASK, like nvme_status_to_pr_err()
already does.
Fixes: 5fd96a4e15de8 ("nvme: Add pr_ops read_keys support")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Reproduced in a QEMU/KVM guest with nvmet-tcp loopback. A TEST-ONLY
injection in the test target (not part of this patch) makes it reject
Extended Data Structure reservation reports with Host Identifier
Inconsistent | DNR, emulating a third-party controller, while accepting
the legacy structure.
Unpatched: nvme_pr_resv_report() compares the raw status, the DNR bit
prevents the match, and no legacy retry is sent (one resv_report, eds=1;
read-keys fails). Patched: the masked comparison matches, a second
resv_report with eds=0 is sent and read-keys succeeds.
Regression without the injection: EDS reservation report and read-keys
succeed directly.
drivers/nvme/host/pr.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/host/pr.c b/drivers/nvme/host/pr.c
index f5711702b16a..f0aebf890e07 100644
--- a/drivers/nvme/host/pr.c
+++ b/drivers/nvme/host/pr.c
@@ -219,7 +219,7 @@ static int nvme_pr_resv_report(struct block_device *bdev, void *data,
retry:
ret = __nvme_send_pr_command(bdev, cdw10, cdw11, nvme_cmd_resv_report,
data, data_len);
- if (ret == NVME_SC_HOST_ID_INCONSIST &&
+ if ((ret & NVME_SCT_SC_MASK) == NVME_SC_HOST_ID_INCONSIST &&
cdw11 == NVME_EXTENDED_DATA_STRUCT) {
cdw11 = 0;
*eds = false;
--
2.43.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 2/4] nvmet: read CRTO from the capability register
2026-12-02 3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
2026-12-02 3:47 ` [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent Guixin Liu
@ 2026-12-02 3:47 ` Guixin Liu
2026-12-02 3:47 ` [PATCH 3/4] nvmet: snapshot the passthru command before completing the request Guixin Liu
2026-12-02 3:47 ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list Guixin Liu
3 siblings, 0 replies; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 3:47 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
The CRTO property reports the controller ready timeout, which lives in
the CAP register. nvmet_execute_prop_get() extracts it from CSTS
instead, where only the low bits are defined, so the property always
reads zero. Any host or tool that reads CRTO directly then gets 0
rather than the advertised CAP.TO.
Read NVME_CAP_TIMEOUT() from ctrl->cap.
Fixes: 1e058089d28f5 ("nvmet: implement crto property")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Reproduced in a QEMU/KVM guest with nvmet-tcp loopback by issuing a
fabrics Property Get for CRTO (offset 0x68) and CAP via
NVME_IOCTL_ADMIN_CMD. Unpatched: CRTO reads 0 while CAP.TO is 15.
Patched: CRTO reads 15, matching CAP.TO. No injection needed.
drivers/nvme/target/fabrics-cmd.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/nvme/target/fabrics-cmd.c b/drivers/nvme/target/fabrics-cmd.c
index 6f0fc695e649..35d8c2abfcaf 100644
--- a/drivers/nvme/target/fabrics-cmd.c
+++ b/drivers/nvme/target/fabrics-cmd.c
@@ -69,7 +69,7 @@ static void nvmet_execute_prop_get(struct nvmet_req *req)
val = ctrl->csts;
break;
case NVME_REG_CRTO:
- val = NVME_CAP_TIMEOUT(ctrl->csts);
+ val = NVME_CAP_TIMEOUT(ctrl->cap);
break;
default:
status = NVME_SC_INVALID_FIELD | NVME_STATUS_DNR;
--
2.43.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 3/4] nvmet: snapshot the passthru command before completing the request
2026-12-02 3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
2026-12-02 3:47 ` [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent Guixin Liu
2026-12-02 3:47 ` [PATCH 2/4] nvmet: read CRTO from the capability register Guixin Liu
@ 2026-12-02 3:47 ` Guixin Liu
2026-12-02 3:59 ` sashiko-bot
2026-12-02 3:47 ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list Guixin Liu
3 siblings, 1 reply; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 3:47 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
nvmet_passthru_execute_cmd_work() reads req->cmd in nvme_passthru_end()
after nvmet_req_complete(). With the loop transport the nvmet_req is
embedded in the host request's pdu, and the submitter can free that
request as soon as the completion wakes it, racing the work's
post-completion read of req->cmd into a use-after-free.
The effects handling cannot simply move before completion: completing
first is what avoids deadlocking against a concurrent reset that
quiesces the admin queue while the scan work flush is pending. Copy
the command onto the stack before completion and pass the copy to
nvme_passthru_end() instead.
Fixes: bc8fb906b0ff9 ("nvme: handle effects after freeing the request")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Reproduced in a QEMU/KVM guest with nvme-loop and nvmet passthru to a
QEMU nvme backend. Identify Controller takes the passthru work path
(use_workqueue) with non-zero command effects, so nvme_passthru_end()
runs after nvmet_req_complete(). A TEST-ONLY msleep after completion
(not part of this patch) widens the window.
Address tracking shows the host loop request, whose pdu embeds the
nvmet_req, is freed by the submitter ~0.6ms after the completion wakes
it, while the work reads req->cmd ~100ms later (stale opcode returned).
This is a use-after-free. KASAN does not print a splat for this access
in the test kernel (a known module-side detection gap, also seen
elsewhere); the free/read ordering of the same object is the evidence.
Patched: the command is snapshotted onto the stack before completion
and nvme_passthru_end() uses the copy; after completion only the stack
copy is read and the freed request is no longer dereferenced.
The effects handling stays after completion on purpose: moving it
before completion reintroduces the reset deadlock fixed by commit
bc8fb906b0ff9.
Regression without the injection: identify and I/O over loop passthru
work, no use-after-free.
drivers/nvme/target/passthru.c | 10 +++++++++-
1 file changed, 9 insertions(+), 1 deletion(-)
diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
index 2d1aeb84637c..4ed3929011dd 100644
--- a/drivers/nvme/target/passthru.c
+++ b/drivers/nvme/target/passthru.c
@@ -231,6 +231,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
struct request *rq = req->p.rq;
struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl;
struct nvme_ns *ns = rq->q->queuedata;
+ struct nvme_command cmd;
u32 effects;
int status;
@@ -252,12 +253,19 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
} else if (status < 0)
status = NVME_SC_INTERNAL;
+ /*
+ * nvmet_req_complete() may free req synchronously (e.g. the loop
+ * transport), so snapshot the command for nvme_passthru_end(),
+ * which must run after completion to avoid deadlocking against a
+ * concurrent reset.
+ */
+ cmd = *req->cmd;
req->cqe->result = nvme_req(rq)->result;
nvmet_req_complete(req, status);
blk_mq_free_request(rq);
if (effects)
- nvme_passthru_end(ctrl, ns, effects, req->cmd, status);
+ nvme_passthru_end(ctrl, ns, effects, &cmd, status);
}
static enum rq_end_io_ret nvmet_passthru_req_done(struct request *rq,
--
2.43.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list
2026-12-02 3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
` (2 preceding siblings ...)
2026-12-02 3:47 ` [PATCH 3/4] nvmet: snapshot the passthru command before completing the request Guixin Liu
@ 2026-12-02 3:47 ` Guixin Liu
2026-12-02 4:01 ` sashiko-bot
3 siblings, 1 reply; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 3:47 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
The DH group negotiation loop adopts the first offered group that
differs from the configured one and never assigns it, so the
configured group is kept even when the host did not offer it, against
the negotiation rule that the controller select from the host's list.
The fallback path is only reached for entries equal to the configured
group, which defeats its purpose.
Mirror the hash negotiation loop: record the first usable offered
group as the fallback, then adopt the configured group when the host
offers it. When falling back, regenerate the DH context with
nvmet_setup_dhgroup(), as the key pair was set up for the configured
group at controller initialization. Treat the NULL DH group as usable
like the configfs dhgroup store does, and guard against unknown group
ids.
Fixes: 7a277c37d3522 ("nvmet-auth: Diffie-Hellman key exchange support")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Reproduced in a QEMU/KVM guest with nvmet-tcp and DH-HMAC-CHAP
authentication. The target host is configured for ffdhe2048; a
TEST-ONLY injection in the test host (not part of this patch) makes it
offer only ffdhe3072.
Unpatched: the target keeps ffdhe2048, a group the host did not offer
(observed via the selected-DH-group print). Patched: the target falls
back to the offered ffdhe3072, regenerates the DH context, and
authentication succeeds. An intermediate version that changed the
group without regenerating the DH key pair failed authentication
(host response mismatch); regenerating with nvmet_setup_dhgroup()
fixes that.
Regression without the injection (host offers the full group list):
authentication with the configured group succeeds.
drivers/nvme/target/fabrics-cmd-auth.c | 21 +++++++++++++--------
1 file changed, 13 insertions(+), 8 deletions(-)
diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index 34c2e14d0bd9..96765add5e4d 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;
+ }
}
+ 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 "
--
2.43.7
^ permalink raw reply related [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] nvmet: snapshot the passthru command before completing the request
2026-12-02 3:47 ` [PATCH 3/4] nvmet: snapshot the passthru command before completing the request Guixin Liu
@ 2026-12-02 3:59 ` sashiko-bot
2026-12-02 5:45 ` Guixin Liu
0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-12-02 3:59 UTC (permalink / raw)
To: Guixin Liu; +Cc: linux-nvme
Thank you for your contribution! Sashiko AI review found 1 potential
issue to consider:
- [Medium] nvmet: premature nvmet_req_complete() in
nvmet_passthru_execute_cmd_work()
--
commit 188f07fd6a69f723caceb270fb65872dac163f43
Author: Guixin Liu <kanie@linux.alibaba.com>
nvmet: snapshot the passthru command before completing the request
This commit copies req->cmd onto the stack before nvmet_req_complete() in
nvmet_passthru_execute_cmd_work() so nvme_passthru_end() does not read
req->cmd after the target request may have been freed.
> diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
> index 32ae4b6b59bf0..791540bc8fce0 100644
> --- a/drivers/nvme/target/passthru.c
> +++ b/drivers/nvme/target/passthru.c
> @@ -226,6 +226,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
> struct request *rq = req->p.rq;
> struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl;
> struct nvme_ns *ns = rq->q->queuedata;
> + struct nvme_command cmd;
> u32 effects;
> int status;
>
> @@ -247,12 +248,19 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
> } else if (status < 0)
> status = NVME_SC_INTERNAL;
>
> + /*
> + * nvmet_req_complete() may free req synchronously (e.g. the loop
> + * transport), so snapshot the command for nvme_passthru_end(),
> + * which must run after completion to avoid deadlocking against a
> + * concurrent reset.
> + */
> + cmd = *req->cmd;
> req->cqe->result = nvme_req(rq)->result;
> nvmet_req_complete(req, status);
> blk_mq_free_request(rq);
>
> if (effects)
> - nvme_passthru_end(ctrl, ns, effects, req->cmd, status);
> + nvme_passthru_end(ctrl, ns, effects, &cmd, status);
> }
[Severity: Medium]
Should nvmet_req_complete(req, status) be moved after
nvme_passthru_end() instead of copying req->cmd?
Commit bc8fb906b0ff ("nvme: handle effects after freeing the request")
required nvme_passthru_end() to run after blk_mq_free_request(rq) so the
host request rq transitions to MQ_RQ_IDLE before flush_work(&ctrl->scan_work)
waits on a quiesced admin queue during a reset of ctrl. It did not require
nvmet_req_complete() to run before nvme_passthru_end().
Calling nvmet_req_complete() early drops passthru->ref via
__nvmet_req_complete() -> nvmet_put_passthru_ref() while ctrl is still in
use, and signals completion to the initiator while ctrl is still frozen or
before ctrl->scan_work has finished updating namespaces:
CPU0 (nvmet_wq) CPU1
nvmet_passthru_execute_cmd_work()
nvmet_req_complete(req, status)
...
nvmet_put_passthru_ref()
__nvmet_passthru_ctrl_disable()
wait_for_completion(&passthru->disable_done)
...
nvme_put_ctrl(passthru->ctrl)
blk_mq_free_request(rq)
/* host ctrl removal frees ctrl */
nvme_passthru_end(ctrl, ...) <-- use-after-free on ctrl
Moving nvmet_req_complete(req, status) after blk_mq_free_request(rq) and
nvme_passthru_end() avoids the reset deadlock on rq, keeps req->cmd and
passthru->ref alive across nvme_passthru_end(), and completes the target
request only after command effects have been applied.
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202034707.3844378-1-kanie@linux.alibaba.com?part=3
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list
2026-12-02 3:47 ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list Guixin Liu
@ 2026-12-02 4:01 ` sashiko-bot
2026-12-02 5:49 ` Guixin Liu
0 siblings, 1 reply; 9+ messages in thread
From: sashiko-bot @ 2026-12-02 4:01 UTC (permalink / raw)
To: Guixin Liu; +Cc: linux-nvme
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 <kanie@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
--
Sashiko AI review · https://sashiko.dev/#/patchset/20261202034707.3844378-1-kanie@linux.alibaba.com?part=4
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 3/4] nvmet: snapshot the passthru command before completing the request
2026-12-02 3:59 ` sashiko-bot
@ 2026-12-02 5:45 ` Guixin Liu
0 siblings, 0 replies; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 5:45 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-nvme
在 2026/12/2 11:59, sashiko-bot@kernel.org 写道:
> Thank you for your contribution! Sashiko AI review found 1 potential
> issue to consider:
> - [Medium] nvmet: premature nvmet_req_complete() in
> nvmet_passthru_execute_cmd_work()
> --
>
> commit 188f07fd6a69f723caceb270fb65872dac163f43
> Author: Guixin Liu <kanie@linux.alibaba.com>
>
> nvmet: snapshot the passthru command before completing the request
>
> This commit copies req->cmd onto the stack before nvmet_req_complete() in
> nvmet_passthru_execute_cmd_work() so nvme_passthru_end() does not read
> req->cmd after the target request may have been freed.
>
>> diff --git a/drivers/nvme/target/passthru.c b/drivers/nvme/target/passthru.c
>> index 32ae4b6b59bf0..791540bc8fce0 100644
>> --- a/drivers/nvme/target/passthru.c
>> +++ b/drivers/nvme/target/passthru.c
>> @@ -226,6 +226,7 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
>> struct request *rq = req->p.rq;
>> struct nvme_ctrl *ctrl = nvme_req(rq)->ctrl;
>> struct nvme_ns *ns = rq->q->queuedata;
>> + struct nvme_command cmd;
>> u32 effects;
>> int status;
>>
>> @@ -247,12 +248,19 @@ static void nvmet_passthru_execute_cmd_work(struct work_struct *w)
>> } else if (status < 0)
>> status = NVME_SC_INTERNAL;
>>
>> + /*
>> + * nvmet_req_complete() may free req synchronously (e.g. the loop
>> + * transport), so snapshot the command for nvme_passthru_end(),
>> + * which must run after completion to avoid deadlocking against a
>> + * concurrent reset.
>> + */
>> + cmd = *req->cmd;
>> req->cqe->result = nvme_req(rq)->result;
>> nvmet_req_complete(req, status);
>> blk_mq_free_request(rq);
>>
>> if (effects)
>> - nvme_passthru_end(ctrl, ns, effects, req->cmd, status);
>> + nvme_passthru_end(ctrl, ns, effects, &cmd, status);
>> }
> [Severity: Medium]
> Should nvmet_req_complete(req, status) be moved after
> nvme_passthru_end() instead of copying req->cmd?
>
> Commit bc8fb906b0ff ("nvme: handle effects after freeing the request")
> required nvme_passthru_end() to run after blk_mq_free_request(rq) so the
> host request rq transitions to MQ_RQ_IDLE before flush_work(&ctrl->scan_work)
> waits on a quiesced admin queue during a reset of ctrl. It did not require
> nvmet_req_complete() to run before nvme_passthru_end().
>
> Calling nvmet_req_complete() early drops passthru->ref via
> __nvmet_req_complete() -> nvmet_put_passthru_ref() while ctrl is still in
> use, and signals completion to the initiator while ctrl is still frozen or
> before ctrl->scan_work has finished updating namespaces:
>
> CPU0 (nvmet_wq) CPU1
> nvmet_passthru_execute_cmd_work()
> nvmet_req_complete(req, status)
> ...
> nvmet_put_passthru_ref()
> __nvmet_passthru_ctrl_disable()
> wait_for_completion(&passthru->disable_done)
> ...
> nvme_put_ctrl(passthru->ctrl)
> blk_mq_free_request(rq)
> /* host ctrl removal frees ctrl */
> nvme_passthru_end(ctrl, ...) <-- use-after-free on ctrl
>
> Moving nvmet_req_complete(req, status) after blk_mq_free_request(rq) and
> nvme_passthru_end() avoids the reset deadlock on rq, keeps req->cmd and
> passthru->ref alive across nvme_passthru_end(), and completes the target
> request only after command effects have been applied.
This is better than mine, changed in v2.
>
^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list
2026-12-02 4:01 ` sashiko-bot
@ 2026-12-02 5:49 ` Guixin Liu
0 siblings, 0 replies; 9+ messages in thread
From: Guixin Liu @ 2026-12-02 5:49 UTC (permalink / raw)
To: sashiko-reviews; +Cc: linux-nvme
在 2026/12/2 12:01, sashiko-bot@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@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
>
^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2026-12-02 5:49 UTC | newest]
Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-02 3:47 [PATCH 0/4] nvme: target and host fixes from a drivers/nvme audit Guixin Liu
2026-12-02 3:47 ` [PATCH 1/4] nvme: mask the status before checking for Host Identifier Inconsistent Guixin Liu
2026-12-02 3:47 ` [PATCH 2/4] nvmet: read CRTO from the capability register Guixin Liu
2026-12-02 3:47 ` [PATCH 3/4] nvmet: snapshot the passthru command before completing the request Guixin Liu
2026-12-02 3:59 ` sashiko-bot
2026-12-02 5:45 ` Guixin Liu
2026-12-02 3:47 ` [PATCH 4/4] nvmet-auth: select the configured DH group from the host's list Guixin Liu
2026-12-02 4:01 ` sashiko-bot
2026-12-02 5:49 ` Guixin Liu
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox