[PATCH v3 2/2] nvme-auth: fix data race on ctrl->transaction
Guixin Liu
kanie at linux.alibaba.com
Mon Nov 16 00:12:11 PST 2026
nvme_ctrl_auth_work() queues the DH-HMAC-CHAP exchange of every queue
on nvme-auth-wq without waiting for them, so multiple
nvme_queue_auth_work() instances run concurrently and all increment
ctrl->transaction in nvme_queue_auth_work(). The plain increment is a
data race, and the lost updates hand the same transaction id to
concurrent queues.
The counter does not need to be shared at all: the controller only
echoes the transaction id within a queue, so a per-queue counter is
sufficient. Increment chap->transaction instead, drop the reset in
nvme_auth_reset_dhchap() so the id stays monotonic across
re-authentication, and remove the now unused ctrl->transaction field.
Fixes: f50fff73d620 ("nvme: implement In-Band authentication")
Cc: stable at vger.kernel.org
Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
---
Changes since v2: reworked per review to use a per-queue counter and
drop the shared field entirely (Keith Busch), and the Fixes tag was
added (sashiko). The Reviewed-by on v2 covered the atomic_t version
of this change and is dropped.
---
drivers/nvme/host/auth.c | 3 +--
drivers/nvme/host/nvme.h | 1 -
2 files changed, 1 insertion(+), 3 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 9a3da74dec5a..54f3354ecae9 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -644,7 +644,6 @@ static void nvme_auth_reset_dhchap(struct nvme_dhchap_queue_context *chap)
chap->s1 = 0;
chap->s2 = 0;
chap->bi_directional = false;
- chap->transaction = 0;
memset(chap->c1, 0, sizeof(chap->c1));
memset(chap->c2, 0, sizeof(chap->c2));
mempool_free(chap->buf, nvme_chap_buf_pool);
@@ -764,7 +763,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
return;
}
- chap->transaction = ctrl->transaction++;
+ chap->transaction++;
/* DH-HMAC-CHAP Step 1: send negotiate */
dev_dbg(ctrl->device, "%s: qid %d send negotiate\n",
diff --git a/drivers/nvme/host/nvme.h b/drivers/nvme/host/nvme.h
index 2543e52d6358..e015d3a3e29c 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -463,7 +463,6 @@ struct nvme_ctrl {
struct nvme_dhchap_queue_context *dhchap_ctxs;
struct nvme_dhchap_key *host_key;
struct nvme_dhchap_key *ctrl_key;
- u16 transaction;
#endif
key_serial_t tls_pskid;
--
2.43.7
More information about the Linux-nvme
mailing list