Blob Blame History Raw
From 5ab3bf7122eafe3bf06b147f8d936a976fe810ba Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Tue, 25 May 2021 14:18:10 +0200
Subject: [PATCH 1/4] route/cls: fix cgroup's clone() function

The destination object doesn't have to be allocated because it's
passed as _dst argument. Also, the function doesn't have to copy plain
fields.

(cherry picked from commit 30552e849c38972dd11fafbb8085924987b002cc)
---
 lib/route/cls/cgroup.c | 15 +++++----------
 1 file changed, 5 insertions(+), 10 deletions(-)

diff --git a/lib/route/cls/cgroup.c b/lib/route/cls/cgroup.c
index b145261825f2..2461d22fd595 100644
--- a/lib/route/cls/cgroup.c
+++ b/lib/route/cls/cgroup.c
@@ -36,17 +36,12 @@ static struct nla_policy cgroup_policy[TCA_CGROUP_MAX+1] = {
 
 static int cgroup_clone(void *_dst, void *_src)
 {
-	struct rtnl_cgroup *dst = NULL, *src = _src;
+	struct rtnl_cgroup *dst = _dst, *src = _src;
 
-	dst = calloc(1, sizeof(*dst));
-	if (!dst)
-		return -NLE_NOMEM;
-
-	dst->cg_mask = src->cg_mask;
-	dst->cg_ematch = rtnl_ematch_tree_clone(src->cg_ematch);
-	if (!dst) {
-		free(dst);
-		return -NLE_NOMEM;
+	if (src->cg_ematch) {
+		dst->cg_ematch = rtnl_ematch_tree_clone(src->cg_ematch);
+		if (!dst->cg_ematch)
+			return -NLE_NOMEM;
 	}
 
 	return 0;
-- 
2.31.1


From 6a118c6b3cf8aa8638e057a282acbf06f09c41a8 Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Tue, 25 May 2021 14:33:21 +0200
Subject: [PATCH 2/4] route/link: fix copy-paste error in geneve.c

(cherry picked from commit aa092d1e729acb8b4aa5a3aaf2f228f46bafec5b)
---
 lib/route/link/geneve.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/lib/route/link/geneve.c b/lib/route/link/geneve.c
index 7232b07f8452..9de1e8f1158f 100644
--- a/lib/route/link/geneve.c
+++ b/lib/route/link/geneve.c
@@ -240,7 +240,7 @@ static void geneve_dump_details(struct rtnl_link *link, struct nl_dump_params *p
 
         if (geneve->mask & GENEVE_ATTR_UDP_ZERO_CSUM6_RX) {
                 nl_dump(p, "      udp-zero-csum6-rx ");
-                if (geneve->udp_zero_csum6_tx)
+                if (geneve->udp_zero_csum6_rx)
                         nl_dump_line(p, "enabled (%#x)\n", geneve->udp_zero_csum6_rx);
                 else
                         nl_dump_line(p, "disabled\n");
-- 
2.31.1


From ed42caf2abdfa52fcb35416710bdcfd8189d8878 Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Tue, 25 May 2021 14:42:29 +0200
Subject: [PATCH 3/4] route/qdisc: fix memory leak in netem.c

'data' was leaked when returning -NLE_INVAL. Fix this by using the
cleanup attribute.

(cherry picked from commit d1a151eb6fe603365d93526796b3fa7e64e1c0fd)
---
 lib/route/qdisc/netem.c | 10 ++++------
 1 file changed, 4 insertions(+), 6 deletions(-)

diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c
index 17dee3b7efa4..20df8fd413b2 100644
--- a/lib/route/qdisc/netem.c
+++ b/lib/route/qdisc/netem.c
@@ -26,6 +26,8 @@
 #include <netlink/route/qdisc.h>
 #include <netlink/route/qdisc/netem.h>
 
+#include "netlink-private/utils.h"
+
 /** @cond SKIP */
 #define SCH_NETEM_ATTR_LATENCY		0x0001
 #define SCH_NETEM_ATTR_LIMIT		0x0002
@@ -911,10 +913,10 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
 	int n = 0;
 	size_t i;
 	size_t len = 2048;
-	char *line;
+	_nl_auto_free char *line = NULL;
 	char name[NAME_MAX];
 	char dist_suffix[] = ".dist";
-	int16_t *data;
+	_nl_auto_free int16_t *data = NULL;
 	char *test_suffix;
 
 	/* Check several locations for the dist file */
@@ -955,7 +957,6 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
 			if (endp == p) break;
 
 			if (n >= MAXDIST) {
-				free(line);
 				fclose(f);
 				return -NLE_INVAL;
 			}
@@ -963,11 +964,8 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
 		}
 	}
 
-	free(line);
 	fclose(f);
-
 	i = rtnl_netem_set_delay_distribution_data(qdisc, data, n);
-	free(data);
 	return i;
 }
 
-- 
2.31.1


From f60433f575beb927b69d6a857a0345d1a3206311 Mon Sep 17 00:00:00 2001
From: Beniamino Galvani <bgalvani@redhat.com>
Date: Wed, 16 Jun 2021 11:56:25 +0200
Subject: [PATCH 4/4] route/qdisc: handle error of calloc()

(cherry picked from commit 26f342d09947d5884014ec4a0553c094e41c60bc)
---
 lib/route/qdisc/netem.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/lib/route/qdisc/netem.c b/lib/route/qdisc/netem.c
index 20df8fd413b2..ceb2ad9871d2 100644
--- a/lib/route/qdisc/netem.c
+++ b/lib/route/qdisc/netem.c
@@ -942,9 +942,12 @@ int rtnl_netem_set_delay_distribution(struct rtnl_qdisc *qdisc, const char *dist
 	if (f == NULL)
 		return -nl_syserr2nlerr(errno);
 
-	data = (int16_t *) calloc (MAXDIST, sizeof(int16_t));
-
-	line = (char *) calloc (sizeof(char), len + 1);
+	data = (int16_t *) calloc(MAXDIST, sizeof(int16_t));
+	line = (char *) calloc(sizeof(char), len + 1);
+	if (!data || !line) {
+	    fclose(f);
+	    return -NLE_NOMEM;
+	}
 
 	while (getline(&line, &len, f) != -1) {
 		char *p, *endp;
-- 
2.31.1