Blame SOURCES/0003-nl-reserve-integer-overflow-rh1442723.patch

26dba0
From 4c39012783e0e376603138dddae9cd876bdd01ce Mon Sep 17 00:00:00 2001
26dba0
From: Thomas Haller <thaller@redhat.com>
26dba0
Date: Mon, 6 Feb 2017 22:23:52 +0100
26dba0
Subject: [PATCH 1/2] lib: check for integer-overflow in nlmsg_reserve()
26dba0
26dba0
In general, libnl functions are not robust against calling with
26dba0
invalid arguments. Thus, never call libnl functions with invalid
26dba0
arguments. In case of nlmsg_reserve() this means never provide
26dba0
a @len argument that causes overflow.
26dba0
26dba0
Still, add an additional safeguard to avoid exploiting such bugs.
26dba0
26dba0
Assume that @pad is a trusted, small integer.
26dba0
Assume that n->nm_size is a valid number of allocated bytes (and thus
26dba0
much smaller then SIZE_T_MAX).
26dba0
Assume, that @len may be set to an untrusted value. Then the patch
26dba0
avoids an integer overflow resulting in reserving too few bytes.
26dba0
26dba0
(cherry picked from commit 3e18948f17148e6a3c4255bdeaaf01ef6081ceeb)
26dba0
---
26dba0
 lib/msg.c | 3 +++
26dba0
 1 file changed, 3 insertions(+)
26dba0
26dba0
diff --git a/lib/msg.c b/lib/msg.c
26dba0
index e8a7e99..f30fd2d 100644
26dba0
--- a/lib/msg.c
26dba0
+++ b/lib/msg.c
26dba0
@@ -410,6 +410,9 @@ void *nlmsg_reserve(struct nl_msg *n, size_t len, int pad)
26dba0
 	size_t nlmsg_len = n->nm_nlh->nlmsg_len;
26dba0
 	size_t tlen;
26dba0
 
26dba0
+	if (len > n->nm_size)
26dba0
+		return NULL;
26dba0
+
26dba0
 	tlen = pad ? ((len + (pad - 1)) & ~(pad - 1)) : len;
26dba0
 
26dba0
 	if ((tlen + nlmsg_len) > n->nm_size)
26dba0
-- 
26dba0
2.9.3
26dba0
26dba0
26dba0
From 1b347b7e5892eac5ea71090b8ec6c08756b0dcd4 Mon Sep 17 00:00:00 2001
26dba0
From: Thomas Haller <thaller@redhat.com>
26dba0
Date: Wed, 18 Jan 2017 11:59:23 +0100
26dba0
Subject: [PATCH 2/2] lib/attr.c: check for valid length argument in
26dba0
 nla_reserve()
26dba0
26dba0
https://github.com/thom311/libnl/issues/124
26dba0
(cherry picked from commit c473d59f972c35c5a7363d52ee6ee1e0792de0f8)
26dba0
---
26dba0
 lib/attr.c | 11 +++++++++--
26dba0
 1 file changed, 9 insertions(+), 2 deletions(-)
26dba0
26dba0
diff --git a/lib/attr.c b/lib/attr.c
26dba0
index a3d1b16..0dca3ec 100644
26dba0
--- a/lib/attr.c
26dba0
+++ b/lib/attr.c
26dba0
@@ -457,7 +457,10 @@ struct nlattr *nla_reserve(struct nl_msg *msg, int attrtype, int attrlen)
26dba0
 {
26dba0
 	struct nlattr *nla;
26dba0
 	int tlen;
26dba0
-	
26dba0
+
26dba0
+	if (attrlen < 0)
26dba0
+		return NULL;
26dba0
+
26dba0
 	tlen = NLMSG_ALIGN(msg->nm_nlh->nlmsg_len) + nla_total_size(attrlen);
26dba0
 
26dba0
 	if (tlen > msg->nm_size)
26dba0
@@ -499,8 +502,12 @@ int nla_put(struct nl_msg *msg, int attrtype, int datalen, const void *data)
26dba0
 	struct nlattr *nla;
26dba0
 
26dba0
 	nla = nla_reserve(msg, attrtype, datalen);
26dba0
-	if (!nla)
26dba0
+	if (!nla) {
26dba0
+		if (datalen < 0)
26dba0
+			return -NLE_INVAL;
26dba0
+
26dba0
 		return -NLE_NOMEM;
26dba0
+	}
26dba0
 
26dba0
 	if (datalen > 0) {
26dba0
 		memcpy(nla_data(nla), data, datalen);
26dba0
-- 
26dba0
2.9.3
26dba0