Skip to contentSkip to conversation

nvmet-auth: assign dh_key to NULL after kfree_sensitive

PATCH In review Vitaliy Shevtsov 5 participants 5 messages Sep 16, 2024 – Oct 25, 2024

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

PATCH 1/1 nvmet-auth: assign dh_key to NULL after kfree_sensitive

ctrl->dh_key might be used across multiple calls to nvmet_setup_dhgroup() for the same controller. So it's better to nullify it after release on error path in order to avoid double free later in nvmet_destroy_auth().

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes 7a277c37d352 ("nvmet-auth: Diffie-Hellman key exchange support")
---
 drivers/nvme/target/auth.c | 1 +
 1 file changed, 1 insertion(+)
drivers/nvme/target/auth.c +1 -0
index e900525b7866..7bca64de4a2f 100644
@@ -101,6 +101,7 @@ int nvmet_setup_dhgroup(struct nvmet_ctrl *ctrl, u8 dhgroup_id)
 			pr_debug("%s: ctrl %d failed to generate private key, err %d\n",
 				 __func__, ctrl->cntlid, ret);
 			kfree_sensitive(ctrl->dh_key);
+			ctrl->dh_key = NULL;
 			return ret;
 		}
 		ctrl->dh_keysize = crypto_kpp_maxsize(ctrl->dh_tfm);
Signature · 1 line
2.46.1
maintainer Reviewed-by on v1 1/1
#1 lore raw
Quoted 4 lines · Vitaliy Shevtsov

ctrl->dh_key might be used across multiple calls to nvmet_setup_dhgroup() for the same controller. So it's better to nullify it after release on error path in order to avoid double free later in nvmet_destroy_auth().

Quoted 9 lines

Found by Linux Verification Center (linuxtesting.org) with Svace.

Fixes 7a277c37d352 ("nvmet-auth: Diffie-Hellman key exchange support")
---
  drivers/nvme/target/auth.c | 1 +
  1 file changed, 1 insertion(+)

Now that is obviously correct.

Cheers,

Hannes

Signature · 4 lines
Dr. Hannes Reinecke                  Kernel Storage Architect
[email protected]                                +49 911 74053 688
SUSE Software Solutions GmbH, Frankenstr. 146, 90461 Nürnberg
HRB 36809 (AG Nürnberg), GF: I. Totev, A. McDonald, W. Knoblich
maintainer
#4 lore raw
Quoted 2 lines · Fedor Pchelkin

I suspect the patch has been lost - it's still missing on nvme-6.12 or nvme-6.13 at git.infradead.org/nvme.git.

Thanks for the ping. Patch applied to nvme-6.12.