Commit b19122a4 authored by Chengguang Xu's avatar Chengguang Xu Committed by Greg Kroah-Hartman

nvme: fix potential memory leak in option parsing

[ Upstream commit 59a2f3f0 ]

When specifying same string type option several times,
current option parsing may cause memory leak. Hence,
call kfree for previous one in this case.
Signed-off-by: default avatarChengguang Xu <cgxu519@gmx.com>
Reviewed-by: default avatarChristoph Hellwig <hch@lst.de>
Reviewed-by: default avatarSagi Grimberg <sagi@grimberg.me>
Signed-off-by: default avatarKeith Busch <keith.busch@intel.com>
Signed-off-by: default avatarJens Axboe <axboe@kernel.dk>
Signed-off-by: default avatarSasha Levin <alexander.levin@microsoft.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
parent 665d3c7f
...@@ -587,6 +587,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, ...@@ -587,6 +587,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
kfree(opts->transport);
opts->transport = p; opts->transport = p;
break; break;
case NVMF_OPT_NQN: case NVMF_OPT_NQN:
...@@ -595,6 +596,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, ...@@ -595,6 +596,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
kfree(opts->subsysnqn);
opts->subsysnqn = p; opts->subsysnqn = p;
nqnlen = strlen(opts->subsysnqn); nqnlen = strlen(opts->subsysnqn);
if (nqnlen >= NVMF_NQN_SIZE) { if (nqnlen >= NVMF_NQN_SIZE) {
...@@ -617,6 +619,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, ...@@ -617,6 +619,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
kfree(opts->traddr);
opts->traddr = p; opts->traddr = p;
break; break;
case NVMF_OPT_TRSVCID: case NVMF_OPT_TRSVCID:
...@@ -625,6 +628,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, ...@@ -625,6 +628,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
kfree(opts->trsvcid);
opts->trsvcid = p; opts->trsvcid = p;
break; break;
case NVMF_OPT_QUEUE_SIZE: case NVMF_OPT_QUEUE_SIZE:
...@@ -706,6 +710,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, ...@@ -706,6 +710,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
nvmf_host_put(opts->host);
opts->host = nvmf_host_add(p); opts->host = nvmf_host_add(p);
kfree(p); kfree(p);
if (!opts->host) { if (!opts->host) {
...@@ -731,6 +736,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts, ...@@ -731,6 +736,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM; ret = -ENOMEM;
goto out; goto out;
} }
kfree(opts->host_traddr);
opts->host_traddr = p; opts->host_traddr = p;
break; break;
case NVMF_OPT_HOST_ID: case NVMF_OPT_HOST_ID:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment