Blob Blame History Raw
From 09fc004d3ca14f16219ac42bc87a6b8e3050dbef Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Thu, 17 Sep 2015 18:48:45 +0200
Subject: [PATCH 1/2] platform: stack-allocate request data for
 nmp_utils_ethtool_get_permanent_address()

(cherry picked from commit 2e66aea123fb6d504ab0e447d1b7bff0ba0a785b)
(cherry picked from commit 6839a5f9e32dc1f7c52c51a18751242baad3659b)
---
 src/platform/nm-platform-utils.c | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index b7f0947..795e23a 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -139,21 +139,24 @@ nmp_utils_ethtool_get_permanent_address (const char *ifname,
                                          guint8 *buf,
                                          size_t *length)
 {
-	gs_free struct ethtool_perm_addr *epaddr = NULL;
+	struct {
+		struct ethtool_perm_addr e;
+		guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1];
+	} edata;
 
 	if (!ifname)
 		return FALSE;
 
-	epaddr = g_malloc0 (sizeof (*epaddr) + NM_UTILS_HWADDR_LEN_MAX);
-	epaddr->cmd = ETHTOOL_GPERMADDR;
-	epaddr->size = NM_UTILS_HWADDR_LEN_MAX;
+	memset (&edata, 0, sizeof (edata));
+	edata.e.cmd = ETHTOOL_GPERMADDR;
+	edata.e.size = NM_UTILS_HWADDR_LEN_MAX;
 
-	if (!ethtool_get (ifname, epaddr))
+	if (!ethtool_get (ifname, &edata.e))
 		return FALSE;
 
-	g_assert (epaddr->size <= NM_UTILS_HWADDR_LEN_MAX);
-	memcpy (buf, epaddr->data, epaddr->size);
-	*length = epaddr->size;
+	g_assert (edata.e.size <= NM_UTILS_HWADDR_LEN_MAX);
+	memcpy (buf, edata.e.data, edata.e.size);
+	*length = edata.e.size;
 	return TRUE;
 }
 
-- 
2.4.3


From 9097a488c8a72ac6a935a452dd9db3df9c28232c Mon Sep 17 00:00:00 2001
From: Thomas Haller <thaller@redhat.com>
Date: Thu, 17 Sep 2015 19:53:56 +0200
Subject: [PATCH 2/2] platform: don't accept 00:00:00:00:00:00 as valid
 permanent address

In nmp_utils_ethtool_get_permanent_address(), don' accept a permanent
address of all zeros.

https://bugzilla.redhat.com/show_bug.cgi?id=1264024
(cherry picked from commit 2733aacd6495f2bdba81ddda617c9a506abd9e73)
(cherry picked from commit 0f18a2ed23f9b6a966738d56556c15cdd6e9e44c)
---
 src/platform/nm-platform-utils.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/src/platform/nm-platform-utils.c b/src/platform/nm-platform-utils.c
index 795e23a..051a873 100644
--- a/src/platform/nm-platform-utils.c
+++ b/src/platform/nm-platform-utils.c
@@ -143,6 +143,7 @@ nmp_utils_ethtool_get_permanent_address (const char *ifname,
 		struct ethtool_perm_addr e;
 		guint8 _extra_data[NM_UTILS_HWADDR_LEN_MAX + 1];
 	} edata;
+	guint zeros[NM_UTILS_HWADDR_LEN_MAX] = { 0 };
 
 	if (!ifname)
 		return FALSE;
@@ -155,6 +156,12 @@ nmp_utils_ethtool_get_permanent_address (const char *ifname,
 		return FALSE;
 
 	g_assert (edata.e.size <= NM_UTILS_HWADDR_LEN_MAX);
+
+	/* Some drivers might return a permanent address of all zeros.
+	 * Reject that (rh#1264024) */
+	if (memcmp (edata.e.data, zeros, edata.e.size) == 0)
+		return FALSE;
+
 	memcpy (buf, edata.e.data, edata.e.size);
 	*length = edata.e.size;
 	return TRUE;
-- 
2.4.3