[PATCH v4 7/9] nvme-auth: wait for authentication to finish when changing keys

From: Hannes Reinecke

Date: Fri Nov 20 2026 - 06:14:55 EST


When changing DH-HMAC-CHAP keys in sysfs we need to wait for authentication
to complete on all queues. Otherwise the user might change the keys while
authentication is in progress, causing the authentication to fail and
I/O to be interrupted.

Signed-off-by: Hannes Reinecke <hare@xxxxxxxxxx>
Reviewed-by: Sagi Grimberg <sagi@xxxxxxxxxxx>
---
drivers/nvme/host/sysfs.c | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/drivers/nvme/host/sysfs.c b/drivers/nvme/host/sysfs.c
index 47caed2ce39786848a5acdb1dc50e4b156694086..ce327a018b0d0a24e26a7f9bfce761157aafe871 100644
--- a/drivers/nvme/host/sysfs.c
+++ b/drivers/nvme/host/sysfs.c
@@ -875,7 +875,6 @@ static ssize_t dhchap_secret_store(struct device *dev,
if (generated) {
dev_dbg(ctrl->dev, "revoke host key %08x\n", key_serial(key));
key_revoke(key);
- synchronize_rcu();
}
key_put(key);
kfree_sensitive(dhchap_secret);
@@ -897,7 +896,7 @@ static ssize_t dhchap_secret_store(struct device *dev,
/* Start re-authentication */
dev_info(ctrl->device, "re-authenticating controller\n");
queue_work(nvme_wq, &ctrl->dhchap_auth_work);
-
+ flush_work(&ctrl->dhchap_auth_work);
return count;
}

@@ -973,7 +972,6 @@ static ssize_t dhchap_ctrl_secret_store(struct device *dev,
dev_dbg(ctrl->dev, "revoke ctrl key %08x\n",
key_serial(old_key));
key_revoke(old_key);
- synchronize_rcu();
}
ctrl->ctrl_key = key;
ctrl->ctrl_key_generated = generated;
@@ -983,7 +981,7 @@ static ssize_t dhchap_ctrl_secret_store(struct device *dev,
/* Start re-authentication */
dev_info(ctrl->device, "re-authenticating controller\n");
queue_work(nvme_wq, &ctrl->dhchap_auth_work);
-
+ flush_work(&ctrl->dhchap_auth_work);
return count;
}


--
2.51.0