Skip to contentSkip to conversation

ip-link: Fix use after free in nl_get_ll_addr_len()

PATCH New Phil Sutter 1 participant 1 message Mar 1, 2018

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 ip-link: Fix use after free in nl_get_ll_addr_len()

Immediately after freeing the buffer returned from rtnl_talk(), it is accessed again via pointer in struct rtattr array. This leads to some builds not allowing to set an interface's MAC address because the expected length value is garbage.

Fixes 86bf43c7c2fdc ("lib/libnetlink: update rtnl_talk to support malloc buff at run time")
---
 ip/iplink.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
ip/iplink.c +2 -1
index 230f4c5377d9f..d401311bcad9f 100644
@@ -276,8 +276,9 @@ static int nl_get_ll_addr_len(unsigned int dev_index)
 		return -1;
 	}
 
+	len = RTA_PAYLOAD(tb[IFLA_ADDRESS]);
 	free(answer);
-	return RTA_PAYLOAD(tb[IFLA_ADDRESS]);
+	return len;
 }
 
 static void iplink_parse_vf_vlan_info(int vf, int *argcp, char ***argvp,
Signature · 1 line
2.16.1