nvmet: Free the old negotiation state when restarting authentication
Subsystems (3)
PATCH v2 1/1 nvmet: Free the old negotiation state when restarting authentication
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.
---
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(+)
drivers/nvme/target/auth.c +1 -0
@@ -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)
drivers/nvme/target/fabrics-cmd-auth.c +1 -0
@@ -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);
Signature · 1 line
2.43.7
Looks good:
Quoted 10 lines · Guixin Liu
Restarting a DH-HMAC-CHAP negotiation with SEND(NEGOTIATE) resets
sq->dhchap_stepbut does not release the previous c1/c2/skey, which are only freed innvmet_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.
Quoted 5 lines
Clear the old negotiation state with
nvmet_auth_sq_free()before setting up the new one. Also resetdhchap_skey_lento 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.