]> www.infradead.org Git - nvme.git/commitdiff
nvmet-auth: assign dh_key to NULL after kfree_sensitive
authorVitaliy Shevtsov <v.shevtsov@maxima.ru>
Mon, 16 Sep 2024 17:41:37 +0000 (22:41 +0500)
committerKeith Busch <kbusch@kernel.org>
Wed, 30 Oct 2024 14:19:18 +0000 (07:19 -0700)
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")
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>
drivers/nvme/target/auth.c

index 7897d02c681daa9ecef1bd83656693a14b877d1a..b0fd211ec57ea72df5f62c0d94e900fe1ead8fbd 100644 (file)
@@ -115,6 +115,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);