netfilter-devel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [libnftnl PATCH 0/4] Fix covscan-detected issues
@ 2019-12-02 22:23 Phil Sutter
  2019-12-02 22:23 ` [libnftnl PATCH 1/4] flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs() Phil Sutter
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: Phil Sutter @ 2019-12-02 22:23 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

These are merely memleaks in error paths related to multi device support
in flowtables and netdev family chains.

Phil Sutter (4):
  flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs()
  chain: Fix memleak in error path of nftnl_chain_parse_devs()
  flowtable: Correctly check realloc() call
  chain: Correctly check realloc() call

 src/chain.c     | 12 ++++++------
 src/flowtable.c | 12 ++++++------
 2 files changed, 12 insertions(+), 12 deletions(-)

-- 
2.24.0


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

* [libnftnl PATCH 1/4] flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs()
  2019-12-02 22:23 [libnftnl PATCH 0/4] Fix covscan-detected issues Phil Sutter
@ 2019-12-02 22:23 ` Phil Sutter
  2019-12-02 22:23 ` [libnftnl PATCH 2/4] chain: Fix memleak in error path of nftnl_chain_parse_devs() Phil Sutter
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2019-12-02 22:23 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

In error case, allocated dev_array is not freed.

Fixes: 7f99639dd9217 ("flowtable: device array dynamic allocation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/flowtable.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/flowtable.c b/src/flowtable.c
index 324e80f7e6ad6..db319434b51c0 100644
--- a/src/flowtable.c
+++ b/src/flowtable.c
@@ -419,6 +419,7 @@ static int nftnl_flowtable_parse_devs(struct nlattr *nest,
 err:
 	while (len--)
 		xfree(dev_array[len]);
+	xfree(dev_array);
 	return -1;
 }
 
-- 
2.24.0


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

* [libnftnl PATCH 2/4] chain: Fix memleak in error path of nftnl_chain_parse_devs()
  2019-12-02 22:23 [libnftnl PATCH 0/4] Fix covscan-detected issues Phil Sutter
  2019-12-02 22:23 ` [libnftnl PATCH 1/4] flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs() Phil Sutter
@ 2019-12-02 22:23 ` Phil Sutter
  2019-12-02 22:24 ` [libnftnl PATCH 3/4] flowtable: Correctly check realloc() call Phil Sutter
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2019-12-02 22:23 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

In error case, dev_array is not freed when it should.

Fixes: e3ac19b5ec162 ("chain: multi-device support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/chain.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/src/chain.c b/src/chain.c
index d4050d28e77d0..9cc8735a4936f 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -636,6 +636,7 @@ static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c)
 err:
 	while (len--)
 		xfree(dev_array[len]);
+	xfree(dev_array);
 	return -1;
 }
 
-- 
2.24.0


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

* [libnftnl PATCH 3/4] flowtable: Correctly check realloc() call
  2019-12-02 22:23 [libnftnl PATCH 0/4] Fix covscan-detected issues Phil Sutter
  2019-12-02 22:23 ` [libnftnl PATCH 1/4] flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs() Phil Sutter
  2019-12-02 22:23 ` [libnftnl PATCH 2/4] chain: Fix memleak in error path of nftnl_chain_parse_devs() Phil Sutter
@ 2019-12-02 22:24 ` Phil Sutter
  2019-12-02 22:24 ` [libnftnl PATCH 4/4] chain: " Phil Sutter
  2019-12-02 23:50 ` [libnftnl PATCH 0/4] Fix covscan-detected issues Pablo Neira Ayuso
  4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2019-12-02 22:24 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

If realloc() fails, it returns NULL but the original pointer is
untouchted and therefore still has to be freed. Unconditionally
overwriting the old pointer is therefore a bad idea, use a temporary
variable instead.

Fixes: 7f99639dd9217 ("flowtable: device array dynamic allocation")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/flowtable.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/flowtable.c b/src/flowtable.c
index db319434b51c0..9ba3b6d9a3404 100644
--- a/src/flowtable.c
+++ b/src/flowtable.c
@@ -388,7 +388,7 @@ static int nftnl_flowtable_parse_hook_cb(const struct nlattr *attr, void *data)
 static int nftnl_flowtable_parse_devs(struct nlattr *nest,
 				      struct nftnl_flowtable *c)
 {
-	const char **dev_array;
+	const char **dev_array, **tmp;
 	int len = 0, size = 8;
 	struct nlattr *attr;
 
@@ -401,14 +401,13 @@ static int nftnl_flowtable_parse_devs(struct nlattr *nest,
 			goto err;
 		dev_array[len++] = strdup(mnl_attr_get_str(attr));
 		if (len >= size) {
-			dev_array = realloc(dev_array,
-					    size * 2 * sizeof(char *));
-			if (!dev_array)
+			tmp = realloc(dev_array, size * 2 * sizeof(char *));
+			if (!tmp)
 				goto err;
 
 			size *= 2;
-			memset(&dev_array[len], 0,
-			       (size - len) * sizeof(char *));
+			memset(&tmp[len], 0, (size - len) * sizeof(char *));
+			dev_array = tmp;
 		}
 	}
 
-- 
2.24.0


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

* [libnftnl PATCH 4/4] chain: Correctly check realloc() call
  2019-12-02 22:23 [libnftnl PATCH 0/4] Fix covscan-detected issues Phil Sutter
                   ` (2 preceding siblings ...)
  2019-12-02 22:24 ` [libnftnl PATCH 3/4] flowtable: Correctly check realloc() call Phil Sutter
@ 2019-12-02 22:24 ` Phil Sutter
  2019-12-02 23:50 ` [libnftnl PATCH 0/4] Fix covscan-detected issues Pablo Neira Ayuso
  4 siblings, 0 replies; 6+ messages in thread
From: Phil Sutter @ 2019-12-02 22:24 UTC (permalink / raw)
  To: Pablo Neira Ayuso; +Cc: netfilter-devel

If realloc() fails, it returns NULL but the original pointer is
untouchted and therefore still has to be freed. Unconditionally
overwriting the old pointer is therefore a bad idea, use a temporary
variable instead.

Fixes: e3ac19b5ec162 ("chain: multi-device support")
Signed-off-by: Phil Sutter <phil@nwl.cc>
---
 src/chain.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/src/chain.c b/src/chain.c
index 9cc8735a4936f..b9a16fc9b42df 100644
--- a/src/chain.c
+++ b/src/chain.c
@@ -605,7 +605,7 @@ static int nftnl_chain_parse_hook_cb(const struct nlattr *attr, void *data)
 
 static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c)
 {
-	const char **dev_array;
+	const char **dev_array, **tmp;
 	int len = 0, size = 8;
 	struct nlattr *attr;
 
@@ -618,14 +618,13 @@ static int nftnl_chain_parse_devs(struct nlattr *nest, struct nftnl_chain *c)
 			goto err;
 		dev_array[len++] = strdup(mnl_attr_get_str(attr));
 		if (len >= size) {
-			dev_array = realloc(dev_array,
-					    size * 2 * sizeof(char *));
-			if (!dev_array)
+			tmp = realloc(dev_array, size * 2 * sizeof(char *));
+			if (!tmp)
 				goto err;
 
 			size *= 2;
-			memset(&dev_array[len], 0,
-			       (size - len) * sizeof(char *));
+			memset(&tmp[len], 0, (size - len) * sizeof(char *));
+			dev_array = tmp;
 		}
 	}
 
-- 
2.24.0


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

* Re: [libnftnl PATCH 0/4] Fix covscan-detected issues
  2019-12-02 22:23 [libnftnl PATCH 0/4] Fix covscan-detected issues Phil Sutter
                   ` (3 preceding siblings ...)
  2019-12-02 22:24 ` [libnftnl PATCH 4/4] chain: " Phil Sutter
@ 2019-12-02 23:50 ` Pablo Neira Ayuso
  4 siblings, 0 replies; 6+ messages in thread
From: Pablo Neira Ayuso @ 2019-12-02 23:50 UTC (permalink / raw)
  To: Phil Sutter; +Cc: netfilter-devel

On Mon, Dec 02, 2019 at 11:23:57PM +0100, Phil Sutter wrote:
> These are merely memleaks in error paths related to multi device support
> in flowtables and netdev family chains.

Acked-by: Pablo Neira Ayuso <pablo@netfilter.org>

Thanks for fixing up these, Phil.

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

end of thread, other threads:[~2019-12-02 23:50 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-02 22:23 [libnftnl PATCH 0/4] Fix covscan-detected issues Phil Sutter
2019-12-02 22:23 ` [libnftnl PATCH 1/4] flowtable: Fix memleak in error path of nftnl_flowtable_parse_devs() Phil Sutter
2019-12-02 22:23 ` [libnftnl PATCH 2/4] chain: Fix memleak in error path of nftnl_chain_parse_devs() Phil Sutter
2019-12-02 22:24 ` [libnftnl PATCH 3/4] flowtable: Correctly check realloc() call Phil Sutter
2019-12-02 22:24 ` [libnftnl PATCH 4/4] chain: " Phil Sutter
2019-12-02 23:50 ` [libnftnl PATCH 0/4] Fix covscan-detected issues Pablo Neira Ayuso

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).