nvme: fix dhchap secret memleaks in auth code
PATCH 1/1 nvme: fix dhchap secret memleaks in auth code
Re-authentication through the sysfs interface without changing the PSK will result in a memory leak. This was tested with blktests nvme/045.
Fixes f50fff73d620 ("nvme: implement In-Band authentication")
Signed-off-by Chris Leech <[email protected]>
--- drivers/nvme/host/core.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-)
drivers/nvme/host/core.c +10 -2
@@ -3828,8 +3828,10 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev,int ret; ret =nvme_auth_generate_key (dhchap_secret, &key); -if (ret) +if (ret) { +kfree (dhchap_secret);return ret; + }kfree (opts->dhchap_secret); opts->dhchap_secret = dhchap_secret; host_key = ctrl->host_key;
@@ -3837,6 +3839,8 @@ static ssize_t nvme_ctrl_dhchap_secret_store(struct device *dev, ctrl->host_key = key;mutex_unlock (&ctrl->dhchap_auth_mutex);nvme_auth_free_key (host_key); + }else { +kfree (dhchap_secret); }/* Start re-authentication */ dev_info (ctrl->device,"re-authenticating controller\n" );
@@ -3882,8 +3886,10 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev,int ret; ret =nvme_auth_generate_key (dhchap_secret, &key); -if (ret) +if (ret) { +kfree (dhchap_secret);return ret; + }kfree (opts->dhchap_ctrl_secret); opts->dhchap_ctrl_secret = dhchap_secret; ctrl_key = ctrl->ctrl_key;
@@ -3891,6 +3897,8 @@ static ssize_t nvme_ctrl_dhchap_ctrl_secret_store(struct device *dev, ctrl->ctrl_key = key;mutex_unlock (&ctrl->dhchap_auth_mutex);nvme_auth_free_key (ctrl_key); + }else { +kfree (dhchap_secret); }/* Start re-authentication */ dev_info (ctrl->device,"re-authenticating controller\n" );
Signature · 1 line
2.40.1
Quoted 7 lines · Chris Leech
Re-authentication through the sysfs interface without changing the PSK will result in a memory leak. This was tested with blktests nvme/045.
Fixes f50fff73d620 ("nvme: implement In-Band authentication")Signed-off-by Chris Leech <[email protected]>---
I think it is already fixed in nvme-6.5, if not please let me know ..
-ck
Quoted 5 lines · Chaitanya Kulkarni
Quoted 2 lines · Chris Leech
Re-authentication through the sysfs interface without changing the PSK will result in a memory leak. This was tested with blktests nvme/045.
I think it is already fixed in nvme-6.5, if not please let me know ..
You're right, sorry about that. Looks good in nvme-6.5
- Chris