Skip to contentSkip to conversation

nvmet-auth: always free derived key data

PATCH In review Hannes Reinecke 4 participants 4 messages Apr 25, 2025 – Apr 29, 2025

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 nvmet-auth: always free derived key data

After calling nvme_auth_derive_tls_psk() we need to free the resulting psk data, as either TLS is disable (and we don't need the data anyway) or the psk data is copied into the resulting key (and can be free, too).

Fixes fa2e0f8bbc68 ("nvmet-tcp: support secure channel concatenation")
---
 drivers/nvme/target/auth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvme/target/auth.c +1 -2
index 3f9fad732350..8f67fc21149c 100644
@@ -656,13 +656,12 @@ void nvmet_auth_insert_psk(struct nvmet_sq *sq)
 		pr_warn("%s: ctrl %d qid %d failed to refresh key, error %ld\n",
 			__func__, sq->ctrl->cntlid, sq->qid, PTR_ERR(tls_key));
 		tls_key = NULL;
-		kfree_sensitive(tls_psk);
 	}
 	if (sq->ctrl->tls_key)
 		key_put(sq->ctrl->tls_key);
 	sq->ctrl->tls_key = tls_key;
 #endif
-
+	kfree_sensitive(tls_psk);
 out_free_digest:
 	kfree_sensitive(digest);
 out_free_psk:
Signature · 1 line
2.35.3
Tested-by on v1 1/1
#2 lore raw
In reply to Hannes Reinecke
Quoted 9 lines · Hannes Reinecke

After calling nvme_auth_derive_tls_psk() we need to free the resulting psk data, as either TLS is disable (and we don't need the data anyway) or the psk data is copied into the resulting key (and can be free, too).

Fixes fa2e0f8bbc68 ("nvmet-tcp: support secure channel concatenation")

Thanks for the fix:

Quoted 26 lines
---
 drivers/nvme/target/auth.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)
drivers/nvme/target/auth.c +1 -3
index 3f9fad732350..8f67fc21149c 100644
@@ -656,13 +656,12 @@ void nvmet_auth_insert_psk(struct nvmet_sq *sq)
                pr_warn("%s: ctrl %d qid %d failed to refresh key, error %ld\n",
                        __func__, sq->ctrl->cntlid, sq->qid, PTR_ERR(tls_key));
                tls_key = NULL;
-               kfree_sensitive(tls_psk);
        }
        if (sq->ctrl->tls_key)
                key_put(sq->ctrl->tls_key);
        sq->ctrl->tls_key = tls_key;
 #endif
-
+       kfree_sensitive(tls_psk);
 out_free_digest:
        kfree_sensitive(digest);
 out_free_psk:
--

2.35.3

Signature · 2 lines
Best Regards,
  Yi Zhang