[PATCH 1/2] nvme-core: fix memory leak in dhchap_secret_store

Chaitanya Kulkarni chaitanyak at nvidia.com
Thu Apr 27 01:32:58 PDT 2023


On 4/27/23 01:09, Sagi Grimberg wrote:
> Needs a fixes tag
>
> On 4/27/23 11:04, Chaitanya Kulkarni wrote:
>> Free dhchap_secret in nvme_ctrl_dhchap_secret_store() before we return
>> when nvme_auth_generate_key() returns error.
>>
>> Signed-off-by: Chaitanya Kulkarni <kch at nvidia.com>
>> ---
>>   drivers/nvme/host/core.c | 4 +++-
>>   1 file changed, 3 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/nvme/host/core.c b/drivers/nvme/host/core.c
>> index 518c759346f0..5a9d97c0c0c1 100644
>> --- a/drivers/nvme/host/core.c
>> +++ b/drivers/nvme/host/core.c
>> @@ -3814,8 +3814,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;
>
> Other than that, for this and the next one:
>
> Reviewed-by: Sagi Grimberg <sagi at grimberg.me>

thanks I'll send out V2 with fixes and reviewed-by tag.

-ck




More information about the Linux-nvme mailing list