Blame SOURCES/0001-fix-coverity-issues-rh1606988.patch

f9f3c9
From 79712feff47b2c275cf1cb1291863476ac45070a Mon Sep 17 00:00:00 2001
f9f3c9
From: Thomas Haller <thaller@redhat.com>
f9f3c9
Date: Thu, 8 Aug 2019 10:16:54 +0200
f9f3c9
Subject: [PATCH 1/4] route: fix strncpy() warning from coverity about
f9f3c9
 unterminated string
f9f3c9
f9f3c9
Coverity says:
f9f3c9
f9f3c9
  Error: BUFFER_SIZE_WARNING (CWE-120): [#def1]
f9f3c9
  libnl-3.4.0/lib/route/cls/ematch/text.c:94: buffer_size_warning: Calling strncpy with a maximum size argument of 16 bytes on destination array "t->cfg.algo" of size 16 bytes might leave the destination string unterminated.
f9f3c9
  #   92|   	struct text_data *t = rtnl_ematch_data(e);
f9f3c9
  #   93|
f9f3c9
  #   94|-> 	strncpy(t->cfg.algo, algo, sizeof(t->cfg.algo));
f9f3c9
  #   95|   }
f9f3c9
  #   96|
f9f3c9
f9f3c9
  Error: BUFFER_SIZE_WARNING (CWE-120): [#def11]
f9f3c9
  libnl-3.4.0/lib/xfrm/sa.c:1192: buffer_size_warning: Calling strncpy with a maximum size argument of 64 bytes on destination array "auth->alg_name" of size 64 bytes might leave the destination string unterminated.
f9f3c9
  # 1190|   			}
f9f3c9
  # 1191|
f9f3c9
  # 1192|-> 			strncpy(auth->alg_name, tmpl->auth->alg_name, sizeof(auth->alg_name));
f9f3c9
  # 1193|   			auth->alg_key_len = tmpl->auth->alg_key_len;
f9f3c9
  # 1194|   			memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8);
f9f3c9
f9f3c9
(cherry picked from commit f6f163d68e756d7ee69b93b0ccb4ab24f9764f77)
f9f3c9
---
f9f3c9
 lib/route/cls/ematch/text.c | 1 +
f9f3c9
 lib/xfrm/sa.c               | 1 +
f9f3c9
 2 files changed, 2 insertions(+)
f9f3c9
f9f3c9
diff --git a/lib/route/cls/ematch/text.c b/lib/route/cls/ematch/text.c
f9f3c9
index b14c4abb92a7..12a1e747b48a 100644
f9f3c9
--- a/lib/route/cls/ematch/text.c
f9f3c9
+++ b/lib/route/cls/ematch/text.c
f9f3c9
@@ -92,6 +92,7 @@ void rtnl_ematch_text_set_algo(struct rtnl_ematch *e, const char *algo)
f9f3c9
 	struct text_data *t = rtnl_ematch_data(e);
f9f3c9
 
f9f3c9
 	strncpy(t->cfg.algo, algo, sizeof(t->cfg.algo));
f9f3c9
+	t->cfg.algo[sizeof(t->cfg.algo) - 1] = '\0';
f9f3c9
 }
f9f3c9
 
f9f3c9
 char *rtnl_ematch_text_get_algo(struct rtnl_ematch *e)
f9f3c9
diff --git a/lib/xfrm/sa.c b/lib/xfrm/sa.c
f9f3c9
index 995df9fd9769..15a3661a9699 100644
f9f3c9
--- a/lib/xfrm/sa.c
f9f3c9
+++ b/lib/xfrm/sa.c
f9f3c9
@@ -1190,6 +1190,7 @@ static int build_xfrm_sa_message(struct xfrmnl_sa *tmpl, int cmd, int flags, str
f9f3c9
 			}
f9f3c9
 
f9f3c9
 			strncpy(auth->alg_name, tmpl->auth->alg_name, sizeof(auth->alg_name));
f9f3c9
+			auth->alg_name[sizeof(auth->alg_name) - 1] = '\0';
f9f3c9
 			auth->alg_key_len = tmpl->auth->alg_key_len;
f9f3c9
 			memcpy(auth->alg_key, tmpl->auth->alg_key, (tmpl->auth->alg_key_len + 7) / 8);
f9f3c9
 			if (nla_put(msg, XFRMA_ALG_AUTH, len, auth) < 0) {
f9f3c9
-- 
f9f3c9
2.21.0
f9f3c9
f9f3c9
f9f3c9
From d7b51a8a3d2f0ac0e2c306a77bdf479f64154d43 Mon Sep 17 00:00:00 2001
f9f3c9
From: Thomas Haller <thaller@redhat.com>
f9f3c9
Date: Thu, 8 Aug 2019 10:38:12 +0200
f9f3c9
Subject: [PATCH 2/4] link/sriov: fix memleak in rtnl_link_sriov_clone()
f9f3c9
f9f3c9
Found by Coverity.
f9f3c9
f9f3c9
(cherry picked from commit f1a085994a78a69abcd583d682b9850bc20ed482)
f9f3c9
---
f9f3c9
 lib/route/link/sriov.c | 24 ++++++++++++++++++------
f9f3c9
 1 file changed, 18 insertions(+), 6 deletions(-)
f9f3c9
f9f3c9
diff --git a/lib/route/link/sriov.c b/lib/route/link/sriov.c
f9f3c9
index 5c20ecff68f6..2a87cfe5ff3f 100644
f9f3c9
--- a/lib/route/link/sriov.c
f9f3c9
+++ b/lib/route/link/sriov.c
f9f3c9
@@ -109,8 +109,10 @@ int rtnl_link_sriov_clone(struct rtnl_link *dst, struct rtnl_link *src) {
f9f3c9
 
f9f3c9
 		if (s_vf->ce_mask & SRIOV_ATTR_ADDR) {
f9f3c9
 			vf_addr = nl_addr_clone(s_vf->vf_lladdr);
f9f3c9
-			if (!vf_addr)
f9f3c9
+			if (!vf_addr) {
f9f3c9
+				rtnl_link_vf_put(d_vf);
f9f3c9
 				return -NLE_NOMEM;
f9f3c9
+			}
f9f3c9
 			d_vf->vf_lladdr = vf_addr;
f9f3c9
 		}
f9f3c9
 
f9f3c9
@@ -120,8 +122,10 @@ int rtnl_link_sriov_clone(struct rtnl_link *dst, struct rtnl_link *src) {
f9f3c9
 
f9f3c9
 			err = rtnl_link_vf_vlan_alloc(&dst_vlans,
f9f3c9
 						      src_vlans->size);
f9f3c9
-			if (err < 0)
f9f3c9
+			if (err < 0) {
f9f3c9
+				rtnl_link_vf_put(d_vf);
f9f3c9
 				return err;
f9f3c9
+			}
f9f3c9
 			dst_vlan_info = dst_vlans->vlans;
f9f3c9
 			memcpy(dst_vlans, src_vlans, sizeof(nl_vf_vlans_t));
f9f3c9
 			memcpy(dst_vlan_info, src_vlan_info,
f9f3c9
@@ -558,8 +562,10 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
f9f3c9
 
f9f3c9
 			vf_data->vf_lladdr = nl_addr_build(AF_LLC,
f9f3c9
 							   vf_lladdr->mac, 6);
f9f3c9
-			if (vf_data->vf_lladdr == NULL)
f9f3c9
+			if (vf_data->vf_lladdr == NULL) {
f9f3c9
+				rtnl_link_vf_put(vf_data);
f9f3c9
 				return -NLE_NOMEM;
f9f3c9
+			}
f9f3c9
 			nl_addr_set_family(vf_data->vf_lladdr, AF_LLC);
f9f3c9
 			vf_data->ce_mask |= SRIOV_ATTR_ADDR;
f9f3c9
 		}
f9f3c9
@@ -576,8 +582,10 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
f9f3c9
 
f9f3c9
 			err = rtnl_link_vf_vlan_info(list_len, vf_vlan_info,
f9f3c9
 						     &vf_vlans);
f9f3c9
-			if (err < 0)
f9f3c9
+			if (err < 0) {
f9f3c9
+				rtnl_link_vf_put(vf_data);
f9f3c9
 				return err;
f9f3c9
+			}
f9f3c9
 
f9f3c9
 			vf_data->vf_vlans = vf_vlans;
f9f3c9
 			vf_data->ce_mask |= SRIOV_ATTR_VLAN;
f9f3c9
@@ -586,8 +594,10 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
f9f3c9
 
f9f3c9
 			if (vf_vlan->vlan) {
f9f3c9
 				err = rtnl_link_vf_vlan_alloc(&vf_vlans, 1);
f9f3c9
-				if (err < 0)
f9f3c9
+				if (err < 0) {
f9f3c9
+					rtnl_link_vf_put(vf_data);
f9f3c9
 					return err;
f9f3c9
+				}
f9f3c9
 
f9f3c9
 				vf_vlans->vlans[0].vf_vlan = vf_vlan->vlan;
f9f3c9
 				vf_vlans->vlans[0].vf_vlan_qos = vf_vlan->qos;
f9f3c9
@@ -649,8 +659,10 @@ int rtnl_link_sriov_parse_vflist(struct rtnl_link *link, struct nlattr **tb) {
f9f3c9
 			err = nla_parse_nested(stb, IFLA_VF_STATS_MAX,
f9f3c9
 					       t[IFLA_VF_STATS],
f9f3c9
 					       sriov_stats_policy);
f9f3c9
-			if (err < 0)
f9f3c9
+			if (err < 0) {
f9f3c9
+				rtnl_link_vf_put(vf_data);
f9f3c9
 				return err;
f9f3c9
+			}
f9f3c9
 
f9f3c9
 			SET_VF_STAT(link, cur, stb,
f9f3c9
 				    RTNL_LINK_VF_STATS_RX_PACKETS,
f9f3c9
-- 
f9f3c9
2.21.0
f9f3c9
f9f3c9
f9f3c9
From 9f910abd4b39015cfdcc78566915ed1d852c0fd1 Mon Sep 17 00:00:00 2001
f9f3c9
From: Thomas Haller <thaller@redhat.com>
f9f3c9
Date: Tue, 27 Aug 2019 14:43:54 +0200
f9f3c9
Subject: [PATCH 3/4] lib: accept %NULL arguments for nl_addr_cmp()
f9f3c9
f9f3c9
Just be more forgiving. Also, this avoids a coverity warning:
f9f3c9
f9f3c9
    Error: FORWARD_NULL (CWE-476): [#def1]
f9f3c9
    libnl-3.4.0/lib/route/addr.c:502: var_compare_op: Comparing "a->a_peer" to null implies that "a->a_peer" might be null.
f9f3c9
    libnl-3.4.0/lib/route/addr.c:513: var_deref_model: Passing null pointer "a->a_peer" to "nl_addr_cmp", which dereferences it.
f9f3c9
    libnl-3.4.0/lib/addr.c:587:8: deref_parm: Directly dereferencing parameter "a".
f9f3c9
    #  585|   int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
f9f3c9
    #  586|   {
f9f3c9
    #  587|-> 	int d = a->a_family - b->a_family;
f9f3c9
    #  588|
f9f3c9
    #  589|   	if (d == 0) {
f9f3c9
f9f3c9
https://bugzilla.redhat.com/show_bug.cgi?id=1606988
f9f3c9
(cherry picked from commit 34708e2ef048f3788f3f2d5018735b27b156d244)
f9f3c9
---
f9f3c9
 lib/addr.c | 10 +++++++++-
f9f3c9
 1 file changed, 9 insertions(+), 1 deletion(-)
f9f3c9
f9f3c9
diff --git a/lib/addr.c b/lib/addr.c
f9f3c9
index c299b402a12b..b43791d52179 100644
f9f3c9
--- a/lib/addr.c
f9f3c9
+++ b/lib/addr.c
f9f3c9
@@ -584,8 +584,16 @@ int nl_addr_shared(const struct nl_addr *addr)
f9f3c9
  */
f9f3c9
 int nl_addr_cmp(const struct nl_addr *a, const struct nl_addr *b)
f9f3c9
 {
f9f3c9
-	int d = a->a_family - b->a_family;
f9f3c9
+	int d;
f9f3c9
+
f9f3c9
+	if (a == b)
f9f3c9
+		return 0;
f9f3c9
+	if (!a)
f9f3c9
+		return -1;
f9f3c9
+	if (!b)
f9f3c9
+		return 1;
f9f3c9
 
f9f3c9
+	d = a->a_family - b->a_family;
f9f3c9
 	if (d == 0) {
f9f3c9
 		d = a->a_len - b->a_len;
f9f3c9
 
f9f3c9
-- 
f9f3c9
2.21.0
f9f3c9
f9f3c9
f9f3c9
From 0fd322bb429228a200cc7935a5b597748faaadf8 Mon Sep 17 00:00:00 2001
f9f3c9
From: Thomas Haller <thaller@redhat.com>
f9f3c9
Date: Tue, 27 Aug 2019 14:58:35 +0200
f9f3c9
Subject: [PATCH 4/4] lib: fix error code from nfnl_exp_build_message()
f9f3c9
f9f3c9
Otherwise we return success but don't actually set the output
f9f3c9
result. This can lead to a crash, in case of out-of-memory.
f9f3c9
f9f3c9
Found by Coverity.
f9f3c9
f9f3c9
https://bugzilla.redhat.com/show_bug.cgi?id=1606988
f9f3c9
(cherry picked from commit f3d5c44d21243d5eb59bfc2878d4977df2fd1369)
f9f3c9
---
f9f3c9
 lib/netfilter/exp.c | 2 ++
f9f3c9
 1 file changed, 2 insertions(+)
f9f3c9
f9f3c9
diff --git a/lib/netfilter/exp.c b/lib/netfilter/exp.c
f9f3c9
index 24ec55f4c374..947eea0d4bcd 100644
f9f3c9
--- a/lib/netfilter/exp.c
f9f3c9
+++ b/lib/netfilter/exp.c
f9f3c9
@@ -490,6 +490,8 @@ static int nfnl_exp_build_message(const struct nfnl_exp *exp, int cmd, int flags
f9f3c9
 	return 0;
f9f3c9
 
f9f3c9
 nla_put_failure:
f9f3c9
+	err = -NLE_NOMEM;
f9f3c9
+
f9f3c9
 err_out:
f9f3c9
 	nlmsg_free(msg);
f9f3c9
 	return err;
f9f3c9
-- 
f9f3c9
2.21.0
f9f3c9