nvmet-auth: assign dh_key to NULL after kfree_sensitive

[ Upstream commit d2f551b1f72b4c508ab9298419f6feadc3b5d791 ]

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: 7a277c37d3 ("nvmet-auth: Diffie-Hellman key exchange support")
Cc: stable@vger.kernel.org
Signed-off-by: Vitaliy Shevtsov <v.shevtsov@maxima.ru>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Hannes Reinecke <hare@suse.de>
Signed-off-by: Keith Busch <kbusch@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
This commit is contained in:
Vitaliy Shevtsov
2024-09-16 22:41:37 +05:00
committed by Greg Kroah-Hartman
parent 618d193924
commit c94e965f76

View File

@@ -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", pr_debug("%s: ctrl %d failed to generate private key, err %d\n",
__func__, ctrl->cntlid, ret); __func__, ctrl->cntlid, ret);
kfree_sensitive(ctrl->dh_key); kfree_sensitive(ctrl->dh_key);
ctrl->dh_key = NULL;
return ret; return ret;
} }
ctrl->dh_keysize = crypto_kpp_maxsize(ctrl->dh_tfm); ctrl->dh_keysize = crypto_kpp_maxsize(ctrl->dh_tfm);