Skip to content

Commit 7f70317

Browse files
alistair23kawasaki
authored andcommitted
nvmet-tcp: Ensure old keys are freed before replacing new ones
Previously after the host sends a REPLACETLSPSK we freed the TLS keys as part of calling nvmet_auth_sq_free() on success. A recent change ensured we don't free the keys, allowing REPLACETLSPSK to work. But that fix results in a kernel memory leak when running ``` nvme_trtype=loop ./check nvme/041 nvme/042 nvme/043 nvme/044 nvme/045 nvme/051 nvme/052 echo scan > /sys/kernel/debug/kmemleak cat /sys/kernel/debug/kmemleak ``` We can't free the keys on a successful DHCHAP operation, otherwise the next REPLACETLSPSK will fail, so instead let's free them before we replace them as part of nvmet_auth_challenge(). This ensures that REPLACETLSPSK works, while also avoiding any memory leaks. Fixes: 2e6eb6b ("nvmet-tcp: Don't free SQ on authentication success") Signed-off-by: Alistair Francis <[email protected]> Reviewed-by: Christoph Hellwig <[email protected]>
1 parent 6a0b974 commit 7f70317

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

drivers/nvme/target/fabrics-cmd-auth.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,13 @@ static int nvmet_auth_challenge(struct nvmet_req *req, void *d, int al)
412412
int hash_len = nvme_auth_hmac_hash_len(ctrl->shash_id);
413413
int data_size = sizeof(*d) + hash_len;
414414

415+
/*
416+
* If replacing the keys then we have previous successful keys
417+
* that might be leaked, so we need to free them here.
418+
*/
419+
if (req->sq->dhchap_c1)
420+
nvmet_auth_sq_free(req->sq);
421+
415422
if (ctrl->dh_tfm)
416423
data_size += ctrl->dh_keysize;
417424
if (al < data_size) {

0 commit comments

Comments
 (0)