patches for DPDK stable branches
 help / color / mirror / Atom feed
* [dpdk-stable] [PATCH] ipc: unlock on failure
@ 2019-05-06 13:11 Aaron Conole
  2019-05-06 13:14 ` David Marchand
  2019-05-06 13:48 ` [dpdk-stable] [PATCH v2] " Aaron Conole
  0 siblings, 2 replies; 8+ messages in thread
From: Aaron Conole @ 2019-05-06 13:11 UTC (permalink / raw)
  To: dev; +Cc: Herakliusz Lipiec, stable, Anatoly Burakov, David Marchand

Reported by Coverity.

Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
Cc: stable@dpdk.org
Cc: Anatoly Burakov <anatoly.burakov@intel.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 lib/librte_eal/common/eal_common_proc.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
index d23728604..3498e6b07 100644
--- a/lib/librte_eal/common/eal_common_proc.c
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -1005,8 +1005,10 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 		/* unlocks the mutex while waiting for response,
 		 * locks on receive
 		 */
-		if (mp_request_sync(path, req, reply, &end))
+		if (mp_request_sync(path, req, reply, &end)) {
+			pthread_mutex_unlock(&pending_requests.lock);
 			goto err;
+		}
 	}
 	pthread_mutex_unlock(&pending_requests.lock);
 	/* unlock the directory */
-- 
2.19.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [PATCH] ipc: unlock on failure
  2019-05-06 13:11 [dpdk-stable] [PATCH] ipc: unlock on failure Aaron Conole
@ 2019-05-06 13:14 ` David Marchand
  2019-05-06 13:22   ` Aaron Conole
  2019-05-06 13:48 ` [dpdk-stable] [PATCH v2] " Aaron Conole
  1 sibling, 1 reply; 8+ messages in thread
From: David Marchand @ 2019-05-06 13:14 UTC (permalink / raw)
  To: Aaron Conole; +Cc: dev, Herakliusz Lipiec, dpdk stable, Anatoly Burakov

On Mon, May 6, 2019 at 3:11 PM Aaron Conole <aconole@redhat.com> wrote:

> Reported by Coverity.
>
> Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
> Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
> Cc: stable@dpdk.org
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---
>  lib/librte_eal/common/eal_common_proc.c | 4 +++-
>  1 file changed, 3 insertions(+), 1 deletion(-)
>
> diff --git a/lib/librte_eal/common/eal_common_proc.c
> b/lib/librte_eal/common/eal_common_proc.c
> index d23728604..3498e6b07 100644
> --- a/lib/librte_eal/common/eal_common_proc.c
> +++ b/lib/librte_eal/common/eal_common_proc.c
> @@ -1005,8 +1005,10 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>                 /* unlocks the mutex while waiting for response,
>                  * locks on receive
>                  */
> -               if (mp_request_sync(path, req, reply, &end))
> +               if (mp_request_sync(path, req, reply, &end)) {
> +                       pthread_mutex_unlock(&pending_requests.lock);
>                         goto err;
> +               }
>         }
>         pthread_mutex_unlock(&pending_requests.lock);
>         /* unlock the directory */
> --
> 2.19.1
>

Unfortunately, I think this is more complex than this.
We will leave a flock() pending and leak some resources from opendir().


-- 
David Marchand

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [PATCH] ipc: unlock on failure
  2019-05-06 13:14 ` David Marchand
@ 2019-05-06 13:22   ` Aaron Conole
  0 siblings, 0 replies; 8+ messages in thread
From: Aaron Conole @ 2019-05-06 13:22 UTC (permalink / raw)
  To: David Marchand; +Cc: dev, Herakliusz Lipiec, dpdk stable, Anatoly Burakov

David Marchand <david.marchand@redhat.com> writes:

> On Mon, May 6, 2019 at 3:11 PM Aaron Conole <aconole@redhat.com> wrote:
>
>  Reported by Coverity.
>
>  Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
>  Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
>  Cc: stable@dpdk.org
>  Cc: Anatoly Burakov <anatoly.burakov@intel.com>
>  Signed-off-by: Aaron Conole <aconole@redhat.com>
>  ---
>   lib/librte_eal/common/eal_common_proc.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
>
>  diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
>  index d23728604..3498e6b07 100644
>  --- a/lib/librte_eal/common/eal_common_proc.c
>  +++ b/lib/librte_eal/common/eal_common_proc.c
>  @@ -1005,8 +1005,10 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
>                  /* unlocks the mutex while waiting for response,
>                   * locks on receive
>                   */
>  -               if (mp_request_sync(path, req, reply, &end))
>  +               if (mp_request_sync(path, req, reply, &end)) {
>  +                       pthread_mutex_unlock(&pending_requests.lock);
>                          goto err;
>  +               }
>          }
>          pthread_mutex_unlock(&pending_requests.lock);
>          /* unlock the directory */
>  -- 
>  2.19.1
>
> Unfortunately, I think this is more complex than this.
> We will leave a flock() pending and leak some resources from opendir().

I completely forgot about it, while double checking the mp_request_sync

You're right, we leak the dirfd, still.

Okay, I think see a better way to write this.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* [dpdk-stable] [PATCH v2] ipc: unlock on failure
  2019-05-06 13:11 [dpdk-stable] [PATCH] ipc: unlock on failure Aaron Conole
  2019-05-06 13:14 ` David Marchand
@ 2019-05-06 13:48 ` Aaron Conole
  2019-05-06 14:02   ` David Marchand
                     ` (2 more replies)
  1 sibling, 3 replies; 8+ messages in thread
From: Aaron Conole @ 2019-05-06 13:48 UTC (permalink / raw)
  To: dev; +Cc: Herakliusz Lipiec, stable, Anatoly Burakov, David Marchand

Reported by Coverity.

Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
Cc: stable@dpdk.org
Cc: Anatoly Burakov <anatoly.burakov@intel.com>
Signed-off-by: Aaron Conole <aconole@redhat.com>
---
 lib/librte_eal/common/eal_common_proc.c | 34 +++++++++++++------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/lib/librte_eal/common/eal_common_proc.c b/lib/librte_eal/common/eal_common_proc.c
index d23728604..1a2259fe3 100644
--- a/lib/librte_eal/common/eal_common_proc.c
+++ b/lib/librte_eal/common/eal_common_proc.c
@@ -934,7 +934,7 @@ int __rte_experimental
 rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 		const struct timespec *ts)
 {
-	int dir_fd, ret = 0;
+	int dir_fd, ret = -1;
 	DIR *mp_dir;
 	struct dirent *ent;
 	struct timeval now;
@@ -947,7 +947,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 	reply->msgs = NULL;
 
 	if (check_input(req) != 0)
-		goto err;
+		goto end;
 
 	if (internal_config.no_shconf) {
 		RTE_LOG(DEBUG, EAL, "No shared files mode enabled, IPC is disabled\n");
@@ -957,7 +957,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 	if (gettimeofday(&now, NULL) < 0) {
 		RTE_LOG(ERR, EAL, "Failed to get current time\n");
 		rte_errno = errno;
-		goto err;
+		goto end;
 	}
 
 	end.tv_nsec = (now.tv_usec * 1000 + ts->tv_nsec) % 1000000000;
@@ -969,9 +969,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 		pthread_mutex_lock(&pending_requests.lock);
 		ret = mp_request_sync(eal_mp_socket_path(), req, reply, &end);
 		pthread_mutex_unlock(&pending_requests.lock);
-		if (ret)
-			goto err;
-		return ret;
+		goto end;
 	}
 
 	/* for primary process, broadcast request, and collect reply 1 by 1 */
@@ -979,7 +977,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 	if (!mp_dir) {
 		RTE_LOG(ERR, EAL, "Unable to open directory %s\n", mp_dir_path);
 		rte_errno = errno;
-		goto err;
+		goto end;
 	}
 
 	dir_fd = dirfd(mp_dir);
@@ -987,9 +985,8 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 	if (flock(dir_fd, LOCK_SH)) {
 		RTE_LOG(ERR, EAL, "Unable to lock directory %s\n",
 			mp_dir_path);
-		closedir(mp_dir);
 		rte_errno = errno;
-		goto err;
+		goto close_end;
 	}
 
 	pthread_mutex_lock(&pending_requests.lock);
@@ -1006,21 +1003,26 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
 		 * locks on receive
 		 */
 		if (mp_request_sync(path, req, reply, &end))
-			goto err;
+			goto unlock_end;
 	}
+	ret = 0;
+
+unlock_end:
 	pthread_mutex_unlock(&pending_requests.lock);
 	/* unlock the directory */
 	flock(dir_fd, LOCK_UN);
 
+close_end:
 	/* dir_fd automatically closed on closedir */
 	closedir(mp_dir);
-	return ret;
 
-err:
-	free(reply->msgs);
-	reply->nb_received = 0;
-	reply->msgs = NULL;
-	return -1;
+end:
+	if (ret) {
+		free(reply->msgs);
+		reply->nb_received = 0;
+		reply->msgs = NULL;
+	}
+	return ret;
 }
 
 int __rte_experimental
-- 
2.19.1


^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [PATCH v2] ipc: unlock on failure
  2019-05-06 13:48 ` [dpdk-stable] [PATCH v2] " Aaron Conole
@ 2019-05-06 14:02   ` David Marchand
  2019-05-08 14:24   ` [dpdk-stable] [dpdk-dev] " Stojaczyk, Dariusz
  2019-05-09 11:50   ` [dpdk-stable] " Burakov, Anatoly
  2 siblings, 0 replies; 8+ messages in thread
From: David Marchand @ 2019-05-06 14:02 UTC (permalink / raw)
  To: Aaron Conole; +Cc: dev, Herakliusz Lipiec, dpdk stable, Anatoly Burakov

On Mon, May 6, 2019 at 3:48 PM Aaron Conole <aconole@redhat.com> wrote:

> Reported by Coverity.
>
>
Coverity issue: 340076

Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
> Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
> Cc: stable@dpdk.org
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---
>  lib/librte_eal/common/eal_common_proc.c | 34 +++++++++++++------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/lib/librte_eal/common/eal_common_proc.c
> b/lib/librte_eal/common/eal_common_proc.c
> index d23728604..1a2259fe3 100644
> --- a/lib/librte_eal/common/eal_common_proc.c
> +++ b/lib/librte_eal/common/eal_common_proc.c
> @@ -934,7 +934,7 @@ int __rte_experimental
>  rte_mp_request_sync(struct rte_mp_msg *req, struct rte_mp_reply *reply,
>                 const struct timespec *ts)
>  {
> -       int dir_fd, ret = 0;
> +       int dir_fd, ret = -1;
>         DIR *mp_dir;
>         struct dirent *ent;
>         struct timeval now;
> @@ -947,7 +947,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         reply->msgs = NULL;
>
>         if (check_input(req) != 0)
> -               goto err;
> +               goto end;
>
>         if (internal_config.no_shconf) {
>                 RTE_LOG(DEBUG, EAL, "No shared files mode enabled, IPC is
> disabled\n");
> @@ -957,7 +957,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         if (gettimeofday(&now, NULL) < 0) {
>                 RTE_LOG(ERR, EAL, "Failed to get current time\n");
>                 rte_errno = errno;
> -               goto err;
> +               goto end;
>         }
>
>         end.tv_nsec = (now.tv_usec * 1000 + ts->tv_nsec) % 1000000000;
> @@ -969,9 +969,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>                 pthread_mutex_lock(&pending_requests.lock);
>                 ret = mp_request_sync(eal_mp_socket_path(), req, reply,
> &end);
>                 pthread_mutex_unlock(&pending_requests.lock);
> -               if (ret)
> -                       goto err;
> -               return ret;
> +               goto end;
>         }
>
>         /* for primary process, broadcast request, and collect reply 1 by
> 1 */
> @@ -979,7 +977,7 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         if (!mp_dir) {
>                 RTE_LOG(ERR, EAL, "Unable to open directory %s\n",
> mp_dir_path);
>                 rte_errno = errno;
> -               goto err;
> +               goto end;
>         }
>
>         dir_fd = dirfd(mp_dir);
> @@ -987,9 +985,8 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>         if (flock(dir_fd, LOCK_SH)) {
>                 RTE_LOG(ERR, EAL, "Unable to lock directory %s\n",
>                         mp_dir_path);
> -               closedir(mp_dir);
>                 rte_errno = errno;
> -               goto err;
> +               goto close_end;
>         }
>
>         pthread_mutex_lock(&pending_requests.lock);
> @@ -1006,21 +1003,26 @@ rte_mp_request_sync(struct rte_mp_msg *req, struct
> rte_mp_reply *reply,
>                  * locks on receive
>                  */
>                 if (mp_request_sync(path, req, reply, &end))
> -                       goto err;
> +                       goto unlock_end;
>         }
> +       ret = 0;
> +
> +unlock_end:
>         pthread_mutex_unlock(&pending_requests.lock);
>         /* unlock the directory */
>         flock(dir_fd, LOCK_UN);
>
> +close_end:
>         /* dir_fd automatically closed on closedir */
>         closedir(mp_dir);
> -       return ret;
>
> -err:
> -       free(reply->msgs);
> -       reply->nb_received = 0;
> -       reply->msgs = NULL;
> -       return -1;
> +end:
> +       if (ret) {
> +               free(reply->msgs);
> +               reply->nb_received = 0;
> +               reply->msgs = NULL;
> +       }
> +       return ret;
>  }
>
>  int __rte_experimental
> --
> 2.19.1
>


LGTM.
Reviewed-by: David Marchand <david.marchand@redhat.com>


-- 
David Marchand

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] ipc: unlock on failure
  2019-05-06 13:48 ` [dpdk-stable] [PATCH v2] " Aaron Conole
  2019-05-06 14:02   ` David Marchand
@ 2019-05-08 14:24   ` Stojaczyk, Dariusz
  2019-05-09 11:50   ` [dpdk-stable] " Burakov, Anatoly
  2 siblings, 0 replies; 8+ messages in thread
From: Stojaczyk, Dariusz @ 2019-05-08 14:24 UTC (permalink / raw)
  To: Aaron Conole, dev
  Cc: Lipiec, Herakliusz, stable, Burakov, Anatoly, David Marchand

> -----Original Message-----
> From: dev [mailto:dev-bounces@dpdk.org] On Behalf Of Aaron Conole
> Sent: Monday, May 6, 2019 3:48 PM
> To: dev@dpdk.org
> Cc: Lipiec, Herakliusz <herakliusz.lipiec@intel.com>; stable@dpdk.org;
> Burakov, Anatoly <anatoly.burakov@intel.com>; David Marchand
> <dmarchan@redhat.com>
> Subject: [dpdk-dev] [PATCH v2] ipc: unlock on failure
> 
> Reported by Coverity.
> 
> Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
> Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
> Cc: stable@dpdk.org
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---

Tested-by: Darek Stojaczyk <dariusz.stojaczyk@intel.com>

This silences ASAN as well. :)

Thanks,
D.

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [PATCH v2] ipc: unlock on failure
  2019-05-06 13:48 ` [dpdk-stable] [PATCH v2] " Aaron Conole
  2019-05-06 14:02   ` David Marchand
  2019-05-08 14:24   ` [dpdk-stable] [dpdk-dev] " Stojaczyk, Dariusz
@ 2019-05-09 11:50   ` Burakov, Anatoly
  2019-05-09 14:31     ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon
  2 siblings, 1 reply; 8+ messages in thread
From: Burakov, Anatoly @ 2019-05-09 11:50 UTC (permalink / raw)
  To: Aaron Conole, dev; +Cc: Herakliusz Lipiec, stable, David Marchand

On 06-May-19 2:48 PM, Aaron Conole wrote:
> Reported by Coverity.

Maybe have a more descriptive commit message?

> 
> Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
> Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
> Cc: stable@dpdk.org
> Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> Signed-off-by: Aaron Conole <aconole@redhat.com>
> ---

Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

-- 
Thanks,
Anatoly

^ permalink raw reply	[flat|nested] 8+ messages in thread

* Re: [dpdk-stable] [dpdk-dev] [PATCH v2] ipc: unlock on failure
  2019-05-09 11:50   ` [dpdk-stable] " Burakov, Anatoly
@ 2019-05-09 14:31     ` Thomas Monjalon
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Monjalon @ 2019-05-09 14:31 UTC (permalink / raw)
  To: Aaron Conole
  Cc: dev, Burakov, Anatoly, Herakliusz Lipiec, stable, David Marchand

09/05/2019 13:50, Burakov, Anatoly:
> On 06-May-19 2:48 PM, Aaron Conole wrote:
> > Reported by Coverity.
> 
> Maybe have a more descriptive commit message?
> 
> > 
> > Fixes: a2a06860b8c4 ("ipc: fix memory leak on request failure")
> > Cc: Herakliusz Lipiec <herakliusz.lipiec@intel.com>
> > Cc: stable@dpdk.org
> > Cc: Anatoly Burakov <anatoly.burakov@intel.com>
> > Signed-off-by: Aaron Conole <aconole@redhat.com>
> > ---
> 
> Acked-by: Anatoly Burakov <anatoly.burakov@intel.com>

Applied, thanks



^ permalink raw reply	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2019-05-09 14:32 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-06 13:11 [dpdk-stable] [PATCH] ipc: unlock on failure Aaron Conole
2019-05-06 13:14 ` David Marchand
2019-05-06 13:22   ` Aaron Conole
2019-05-06 13:48 ` [dpdk-stable] [PATCH v2] " Aaron Conole
2019-05-06 14:02   ` David Marchand
2019-05-08 14:24   ` [dpdk-stable] [dpdk-dev] " Stojaczyk, Dariusz
2019-05-09 11:50   ` [dpdk-stable] " Burakov, Anatoly
2019-05-09 14:31     ` [dpdk-stable] [dpdk-dev] " Thomas Monjalon

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).