[PATCH v2 3/5] nvme-auth: fix data race on ctrl->transaction
Guixin Liu
kanie at linux.alibaba.com
Sun Nov 8 18:26:44 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 controller side only echoes the transaction id within a queue, so
the race has no functional impact today, but the increment is still
unsynchronized and KCSAN reports it. Use atomic_inc_return(); the
first transaction id is now 1 instead of 0, which is immaterial as
the controller only echoes the id within a queue.
Reviewed-by: Hannes Reinecke <hare at kernel.org>
Signed-off-by: Guixin Liu <kanie at linux.alibaba.com>
---
drivers/nvme/host/auth.c | 2 +-
drivers/nvme/host/nvme.h | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/auth.c b/drivers/nvme/host/auth.c
index 85f005a5efd0..c605e8f47e9a 100644
--- a/drivers/nvme/host/auth.c
+++ b/drivers/nvme/host/auth.c
@@ -765,7 +765,7 @@ static void nvme_queue_auth_work(struct work_struct *work)
return;
}
- chap->transaction = ctrl->transaction++;
+ chap->transaction = (u16)atomic_inc_return(&ctrl->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 92c048002ecd..1fb676dade12 100644
--- a/drivers/nvme/host/nvme.h
+++ b/drivers/nvme/host/nvme.h
@@ -446,7 +446,7 @@ struct nvme_ctrl {
struct nvme_dhchap_queue_context *dhchap_ctxs;
struct nvme_dhchap_key *host_key;
struct nvme_dhchap_key *ctrl_key;
- u16 transaction;
+ atomic_t transaction;
#endif
key_serial_t tls_pskid;
--
2.43.7
More information about the Linux-nvme
mailing list