* [PATCH] nvme: fix potential memory leak in option parsing
@ 2018-04-14 12:06 Chengguang Xu
2018-04-15 8:56 ` Sagi Grimberg
2018-04-17 15:17 ` Christoph Hellwig
0 siblings, 2 replies; 4+ messages in thread
From: Chengguang Xu @ 2018-04-14 12:06 UTC (permalink / raw)
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: Chengguang Xu <cgxu519 at gmx.com>
---
drivers/nvme/host/fabrics.c | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/drivers/nvme/host/fabrics.c b/drivers/nvme/host/fabrics.c
index 124c458..7ae732a 100644
--- a/drivers/nvme/host/fabrics.c
+++ b/drivers/nvme/host/fabrics.c
@@ -668,6 +668,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM;
goto out;
}
+ kfree(opts->transport);
opts->transport = p;
break;
case NVMF_OPT_NQN:
@@ -676,6 +677,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM;
goto out;
}
+ kfree(opts->subsysnqn);
opts->subsysnqn = p;
nqnlen = strlen(opts->subsysnqn);
if (nqnlen >= NVMF_NQN_SIZE) {
@@ -698,6 +700,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM;
goto out;
}
+ kfree(opts->traddr);
opts->traddr = p;
break;
case NVMF_OPT_TRSVCID:
@@ -706,6 +709,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM;
goto out;
}
+ kfree(opts->trsvcid);
opts->trsvcid = p;
break;
case NVMF_OPT_QUEUE_SIZE:
@@ -792,6 +796,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -EINVAL;
goto out;
}
+ nvmf_host_put(opts->host);
opts->host = nvmf_host_add(p);
kfree(p);
if (!opts->host) {
@@ -817,6 +822,7 @@ static int nvmf_parse_options(struct nvmf_ctrl_options *opts,
ret = -ENOMEM;
goto out;
}
+ kfree(opts->host_traddr);
opts->host_traddr = p;
break;
case NVMF_OPT_HOST_ID:
--
1.8.3.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH] nvme: fix potential memory leak in option parsing
2018-04-14 12:06 [PATCH] nvme: fix potential memory leak in option parsing Chengguang Xu
@ 2018-04-15 8:56 ` Sagi Grimberg
2018-04-17 15:17 ` Christoph Hellwig
1 sibling, 0 replies; 4+ messages in thread
From: Sagi Grimberg @ 2018-04-15 8:56 UTC (permalink / raw)
Looks good,
Reviewed-by: Sagi Grimberg <sagi at grimberg.me>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] nvme: fix potential memory leak in option parsing
2018-04-14 12:06 [PATCH] nvme: fix potential memory leak in option parsing Chengguang Xu
2018-04-15 8:56 ` Sagi Grimberg
@ 2018-04-17 15:17 ` Christoph Hellwig
2018-04-17 22:07 ` Keith Busch
1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2018-04-17 15:17 UTC (permalink / raw)
Looks good,
Reviewed-by: Christoph Hellwig <hch at lst.de>
^ permalink raw reply [flat|nested] 4+ messages in thread
* [PATCH] nvme: fix potential memory leak in option parsing
2018-04-17 15:17 ` Christoph Hellwig
@ 2018-04-17 22:07 ` Keith Busch
0 siblings, 0 replies; 4+ messages in thread
From: Keith Busch @ 2018-04-17 22:07 UTC (permalink / raw)
Thanks, applied for 4.17-rc2
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2018-04-17 22:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-04-14 12:06 [PATCH] nvme: fix potential memory leak in option parsing Chengguang Xu
2018-04-15 8:56 ` Sagi Grimberg
2018-04-17 15:17 ` Christoph Hellwig
2018-04-17 22:07 ` Keith Busch
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox