* [dm-devel] [PATCH v4 22/29] multipath: fix leaks in check_path_valid()
@ 2020-12-17 10:04 mwilck
2020-12-17 16:32 ` Benjamin Marzinski
0 siblings, 1 reply; 3+ messages in thread
From: mwilck @ 2020-12-17 10:04 UTC (permalink / raw)
To: Christophe Varoqui, Benjamin Marzinski, lixiaokeng; +Cc: dm-devel, Martin Wilck
From: Martin Wilck <mwilck@suse.com>
There were two leaks in check_path_valid(): if path status was
successfully determined before calling store_pathvec(), free_path()
wasn't called. Also, if an error exit occured, neither cleanup
function was called.
This patch fixes both, at the cost of using "static" for the pp and
pathvec variables.
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
multipath/main.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/multipath/main.c b/multipath/main.c
index 1949a1c..043d8fa 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -93,7 +93,7 @@ void rcu_register_thread_memb(void) {}
void rcu_unregister_thread_memb(void) {}
static int
-filter_pathvec (vector pathvec, char * refwwid)
+filter_pathvec (vector pathvec, const char *refwwid)
{
int i;
struct path * pp;
@@ -594,8 +594,9 @@ static int
check_path_valid(const char *name, struct config *conf, bool is_uevent)
{
int fd, r = PATH_IS_ERROR;
- struct path *pp = NULL;
+ struct path *pp;
vector pathvec = NULL;
+ const char *wwid;
pp = alloc_path();
if (!pp)
@@ -664,14 +665,19 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
if (store_path(pathvec, pp) != 0) {
free_path(pp);
+ pp = NULL;
goto fail;
+ } else {
+ /* make sure path isn't freed twice */
+ wwid = pp->wwid;
+ pp = NULL;
}
/* For find_multipaths = SMART, if there is more than one path
* matching the refwwid, then the path is valid */
if (path_discovery(pathvec, DI_SYSFS | DI_WWID) < 0)
goto fail;
- filter_pathvec(pathvec, pp->wwid);
+ filter_pathvec(pathvec, wwid);
if (VECTOR_SIZE(pathvec) > 1)
r = PATH_IS_VALID;
else
@@ -679,21 +685,25 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
out:
r = print_cmd_valid(r, pathvec, conf);
- free_pathvec(pathvec, FREE_PATHS);
/*
* multipath -u must exit with status 0, otherwise udev won't
* import its output.
*/
if (!is_uevent && r == PATH_IS_NOT_VALID)
- return RTVL_FAIL;
- return RTVL_OK;
+ r = RTVL_FAIL;
+ else
+ r = RTVL_OK;
+ goto cleanup;
fail:
- if (pathvec)
- free_pathvec(pathvec, FREE_PATHS);
- else
+ r = RTVL_FAIL;
+
+cleanup:
+ if (pp != NULL)
free_path(pp);
- return RTVL_FAIL;
+ if (pathvec != NULL)
+ free_pathvec(pathvec, FREE_PATHS);
+ return r;
}
static int
--
2.29.0
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [dm-devel] [PATCH v4 22/29] multipath: fix leaks in check_path_valid()
2020-12-17 10:04 [dm-devel] [PATCH v4 22/29] multipath: fix leaks in check_path_valid() mwilck
@ 2020-12-17 16:32 ` Benjamin Marzinski
2020-12-18 15:26 ` [dm-devel] [PATCH v5 22/29] multipath: fix leak " mwilck
0 siblings, 1 reply; 3+ messages in thread
From: Benjamin Marzinski @ 2020-12-17 16:32 UTC (permalink / raw)
To: mwilck; +Cc: lixiaokeng, dm-devel
On Thu, Dec 17, 2020 at 11:04:44AM +0100, mwilck@suse.com wrote:
> From: Martin Wilck <mwilck@suse.com>
>
> There were two leaks in check_path_valid(): if path status was
> successfully determined before calling store_pathvec(), free_path()
> wasn't called. Also, if an error exit occured, neither cleanup
> function was called.
>
> This patch fixes both, at the cost of using "static" for the pp and
> pathvec variables.
>
I just noticed that your commit message doesn't totally match what the
patch does anymore. But the code looks fine. Feel free to change the
message when pushing to upstream-queue.
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
> Signed-off-by: Martin Wilck <mwilck@suse.com>
> ---
> multipath/main.c | 30 ++++++++++++++++++++----------
> 1 file changed, 20 insertions(+), 10 deletions(-)
>
> diff --git a/multipath/main.c b/multipath/main.c
> index 1949a1c..043d8fa 100644
> --- a/multipath/main.c
> +++ b/multipath/main.c
> @@ -93,7 +93,7 @@ void rcu_register_thread_memb(void) {}
> void rcu_unregister_thread_memb(void) {}
>
> static int
> -filter_pathvec (vector pathvec, char * refwwid)
> +filter_pathvec (vector pathvec, const char *refwwid)
> {
> int i;
> struct path * pp;
> @@ -594,8 +594,9 @@ static int
> check_path_valid(const char *name, struct config *conf, bool is_uevent)
> {
> int fd, r = PATH_IS_ERROR;
> - struct path *pp = NULL;
> + struct path *pp;
> vector pathvec = NULL;
> + const char *wwid;
>
> pp = alloc_path();
> if (!pp)
> @@ -664,14 +665,19 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
>
> if (store_path(pathvec, pp) != 0) {
> free_path(pp);
> + pp = NULL;
> goto fail;
> + } else {
> + /* make sure path isn't freed twice */
> + wwid = pp->wwid;
> + pp = NULL;
> }
>
> /* For find_multipaths = SMART, if there is more than one path
> * matching the refwwid, then the path is valid */
> if (path_discovery(pathvec, DI_SYSFS | DI_WWID) < 0)
> goto fail;
> - filter_pathvec(pathvec, pp->wwid);
> + filter_pathvec(pathvec, wwid);
> if (VECTOR_SIZE(pathvec) > 1)
> r = PATH_IS_VALID;
> else
> @@ -679,21 +685,25 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
>
> out:
> r = print_cmd_valid(r, pathvec, conf);
> - free_pathvec(pathvec, FREE_PATHS);
> /*
> * multipath -u must exit with status 0, otherwise udev won't
> * import its output.
> */
> if (!is_uevent && r == PATH_IS_NOT_VALID)
> - return RTVL_FAIL;
> - return RTVL_OK;
> + r = RTVL_FAIL;
> + else
> + r = RTVL_OK;
> + goto cleanup;
>
> fail:
> - if (pathvec)
> - free_pathvec(pathvec, FREE_PATHS);
> - else
> + r = RTVL_FAIL;
> +
> +cleanup:
> + if (pp != NULL)
> free_path(pp);
> - return RTVL_FAIL;
> + if (pathvec != NULL)
> + free_pathvec(pathvec, FREE_PATHS);
> + return r;
> }
>
> static int
> --
> 2.29.0
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply [flat|nested] 3+ messages in thread
* [dm-devel] [PATCH v5 22/29] multipath: fix leak in check_path_valid()
2020-12-17 16:32 ` Benjamin Marzinski
@ 2020-12-18 15:26 ` mwilck
0 siblings, 0 replies; 3+ messages in thread
From: mwilck @ 2020-12-18 15:26 UTC (permalink / raw)
To: Christophe Varoqui, Benjamin Marzinski; +Cc: dm-devel, Martin Wilck
From: Martin Wilck <mwilck@suse.com>
If path status was successfully determined before calling store_pathvec(),
free_path() wasn't called.
Reviewed-by: Benjamin Marzinski <bmarzins@redhat.com>
Signed-off-by: Martin Wilck <mwilck@suse.com>
---
multipath/main.c | 30 ++++++++++++++++++++----------
1 file changed, 20 insertions(+), 10 deletions(-)
diff --git a/multipath/main.c b/multipath/main.c
index 1949a1c..043d8fa 100644
--- a/multipath/main.c
+++ b/multipath/main.c
@@ -93,7 +93,7 @@ void rcu_register_thread_memb(void) {}
void rcu_unregister_thread_memb(void) {}
static int
-filter_pathvec (vector pathvec, char * refwwid)
+filter_pathvec (vector pathvec, const char *refwwid)
{
int i;
struct path * pp;
@@ -594,8 +594,9 @@ static int
check_path_valid(const char *name, struct config *conf, bool is_uevent)
{
int fd, r = PATH_IS_ERROR;
- struct path *pp = NULL;
+ struct path *pp;
vector pathvec = NULL;
+ const char *wwid;
pp = alloc_path();
if (!pp)
@@ -664,14 +665,19 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
if (store_path(pathvec, pp) != 0) {
free_path(pp);
+ pp = NULL;
goto fail;
+ } else {
+ /* make sure path isn't freed twice */
+ wwid = pp->wwid;
+ pp = NULL;
}
/* For find_multipaths = SMART, if there is more than one path
* matching the refwwid, then the path is valid */
if (path_discovery(pathvec, DI_SYSFS | DI_WWID) < 0)
goto fail;
- filter_pathvec(pathvec, pp->wwid);
+ filter_pathvec(pathvec, wwid);
if (VECTOR_SIZE(pathvec) > 1)
r = PATH_IS_VALID;
else
@@ -679,21 +685,25 @@ check_path_valid(const char *name, struct config *conf, bool is_uevent)
out:
r = print_cmd_valid(r, pathvec, conf);
- free_pathvec(pathvec, FREE_PATHS);
/*
* multipath -u must exit with status 0, otherwise udev won't
* import its output.
*/
if (!is_uevent && r == PATH_IS_NOT_VALID)
- return RTVL_FAIL;
- return RTVL_OK;
+ r = RTVL_FAIL;
+ else
+ r = RTVL_OK;
+ goto cleanup;
fail:
- if (pathvec)
- free_pathvec(pathvec, FREE_PATHS);
- else
+ r = RTVL_FAIL;
+
+cleanup:
+ if (pp != NULL)
free_path(pp);
- return RTVL_FAIL;
+ if (pathvec != NULL)
+ free_pathvec(pathvec, FREE_PATHS);
+ return r;
}
static int
--
2.29.0
--
dm-devel mailing list
dm-devel@redhat.com
https://www.redhat.com/mailman/listinfo/dm-devel
^ permalink raw reply related [flat|nested] 3+ messages in thread
end of thread, other threads:[~2020-12-18 15:30 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-12-17 10:04 [dm-devel] [PATCH v4 22/29] multipath: fix leaks in check_path_valid() mwilck
2020-12-17 16:32 ` Benjamin Marzinski
2020-12-18 15:26 ` [dm-devel] [PATCH v5 22/29] multipath: fix leak " mwilck
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.