* [PATCH v2] nvmet: Free the old negotiation state when restarting authentication
@ 2026-10-28 8:55 Guixin Liu
2026-10-28 14:38 ` Christoph Hellwig
2026-10-28 15:49 ` Keith Busch
0 siblings, 2 replies; 3+ messages in thread
From: Guixin Liu @ 2026-10-28 8:55 UTC (permalink / raw)
To: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke
Cc: linux-nvme
Restarting a DH-HMAC-CHAP negotiation with SEND(NEGOTIATE) resets
sq->dhchap_step but does not release the previous c1/c2/skey, which
are only freed in nvmet_auth_sq_free() at teardown. The next
CHALLENGE/REPLY exchange then overwrites those pointers with fresh
allocations.
An unauthenticated host can repeat the negotiate message endlessly,
leaking a few dozen bytes per round and slowly exhausting target
memory.
Clear the old negotiation state with nvmet_auth_sq_free() before
setting up the new one. Also reset dhchap_skey_len to zero: if a DH
session key was already established, a following round with dhvlen=0
would otherwise pass a NULL skey with a stale non-zero length to the
HMAC code and dereference it.
Fixes: db1312dd95488 ("nvmet: implement basic In-Band Authentication")
Cc: stable@vger.kernel.org
Signed-off-by: Guixin Liu <kanie@linux.alibaba.com>
---
Changes since v1:
- Also reset dhchap_skey_len when clearing the old negotiation state,
so a following round with dhvlen=0 cannot pass a NULL skey with a
stale non-zero length to the HMAC code (Sashiko AI review)
drivers/nvme/target/auth.c | 1 +
drivers/nvme/target/fabrics-cmd-auth.c | 1 +
2 files changed, 2 insertions(+)
diff --git a/drivers/nvme/target/auth.c b/drivers/nvme/target/auth.c
index 1680e5e6839c..574025730834 100644
--- a/drivers/nvme/target/auth.c
+++ b/drivers/nvme/target/auth.c
@@ -237,6 +237,7 @@ void nvmet_auth_sq_free(struct nvmet_sq *sq)
sq->dhchap_c2 = NULL;
kfree(sq->dhchap_skey);
sq->dhchap_skey = NULL;
+ sq->dhchap_skey_len = 0;
}
void nvmet_auth_sq_destroy(struct nvmet_sq *sq)
diff --git a/drivers/nvme/target/fabrics-cmd-auth.c b/drivers/nvme/target/fabrics-cmd-auth.c
index bc49b48cdd63..3d9840d37a8b 100644
--- a/drivers/nvme/target/fabrics-cmd-auth.c
+++ b/drivers/nvme/target/fabrics-cmd-auth.c
@@ -330,6 +330,7 @@ void nvmet_execute_auth_send(struct nvmet_req *req)
/* Restart negotiation */
pr_debug("%s: ctrl %d qid %d reset negotiation\n",
__func__, ctrl->cntlid, req->sq->qid);
+ nvmet_auth_sq_free(req->sq);
if (!req->sq->qid) {
dhchap_status = nvmet_setup_auth(ctrl, req->sq,
true);
--
2.43.7
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH v2] nvmet: Free the old negotiation state when restarting authentication
2026-10-28 8:55 [PATCH v2] nvmet: Free the old negotiation state when restarting authentication Guixin Liu
@ 2026-10-28 14:38 ` Christoph Hellwig
2026-10-28 15:49 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Christoph Hellwig @ 2026-10-28 14:38 UTC (permalink / raw)
To: Guixin Liu
Cc: Keith Busch, Jens Axboe, Christoph Hellwig, Sagi Grimberg,
Nilay Shroff, Daniel Wagner, Hannes Reinecke, linux-nvme
Looks good:
Reviewed-by: Christoph Hellwig <hch@lst.de>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH v2] nvmet: Free the old negotiation state when restarting authentication
2026-10-28 8:55 [PATCH v2] nvmet: Free the old negotiation state when restarting authentication Guixin Liu
2026-10-28 14:38 ` Christoph Hellwig
@ 2026-10-28 15:49 ` Keith Busch
1 sibling, 0 replies; 3+ messages in thread
From: Keith Busch @ 2026-10-28 15:49 UTC (permalink / raw)
To: Guixin Liu
Cc: Jens Axboe, Christoph Hellwig, Sagi Grimberg, Nilay Shroff,
Daniel Wagner, Hannes Reinecke, linux-nvme
On Wed, Oct 28, 2026 at 04:55:51PM +0800, Guixin Liu wrote:
> Restarting a DH-HMAC-CHAP negotiation with SEND(NEGOTIATE) resets
> sq->dhchap_step but does not release the previous c1/c2/skey, which
> are only freed in nvmet_auth_sq_free() at teardown. The next
> CHALLENGE/REPLY exchange then overwrites those pointers with fresh
> allocations.
>
> An unauthenticated host can repeat the negotiate message endlessly,
> leaking a few dozen bytes per round and slowly exhausting target
> memory.
>
> Clear the old negotiation state with nvmet_auth_sq_free() before
> setting up the new one. Also reset dhchap_skey_len to zero: if a DH
> session key was already established, a following round with dhvlen=0
> would otherwise pass a NULL skey with a stale non-zero length to the
> HMAC code and dereference it.
Thanks, applied to nvme-7.4.
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2026-10-28 15:50 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-28 8:55 [PATCH v2] nvmet: Free the old negotiation state when restarting authentication Guixin Liu
2026-10-28 14:38 ` Christoph Hellwig
2026-10-28 15:49 ` Keith Busch
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.